The substitution s/\s+ $// is simple and almost as direct: replace a chunk of whitespace followed by the end of the string with nothin.
"It's not as``perfect""as the first one--it matches each chunk of whitespace and examines it to see if it's at the end of the string or not."