in reply to removing all whitespace but newlines

Perhaps something like this, which will remove all whitespace except for newlines, if your line is in $line.
$line =~ s/[^\S\n]+//g;
If you need to remove just trailing whitespace, change it to this:
$line =~ s/[^\S\n]+$//g;

Update: I should point out explicitly that that's a capital S inside the character class... the character class matches anything that's non-non-whitespace (i.e., whitespace) and non-newline.

-- Mike

--
just,my${.02}