in reply to removing the white spaces

$text =~ s{ # Substitute \A # from the beginning of the string \s+ # one or more white space characters }{}xms; # with nothing $text =~ s{ # Substitute \s+ # one or more white space characters \z # from the end of the string }{}xms; # with nothing $text =~ s{ # Substitute \s+ # one or more white space characters }{ }gxms; # with one space, anywhere in the string # As many times as it occurs

Modified my code to address multiple white spaces in the middle of the string and remove white space from the front of the string. This is a little more verbose than the previous poster but I tried to comment each piece to explain it better.