in reply to Replacing whitespaces with a regex

When you have the time read perlre

If you're in a rush... skip down to the section on "Quantifiers". TIMTOWTDI. Pick the way which you think you'll stand the best chance of understanding 3 weeks or 3 months from now when you're asked to tweak your code.


$work =~ s/\s+$/ /; # more than once


$work =~ s/\s{2,}$/ /; # at least twice

should work.