in reply to Replacing whitespace with null
Your problem is that you are using ^ in the beginning of your pattern. ^ matches the beginning of the string, but your whitespaces are not immediately after the beginning; there are letters in the way. Try something like:
$_ =~ s/\s+$//g;
That will remove all whitespace at the end of the string.