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


in reply to Re^3: Strings mangled on printing
in thread Strings mangled on printing

Actually, $inp =~ s/\s$//; will remove only a single whitespace character at the end of the line.

Use $inp =~ s/\s+$//; to remove all of them.