http://www.perlmonks.org?node_id=1021625


in reply to Replacing whitespaces with a regex

Small variation of the previous solutions, replace any spaces (even 1 space) with 1 space:

for ( @array ) { s/\s+$/ / }