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

Q&A > regular expressions > How do I remove whitespace at the beginning or end of my string? - Answer contributed by trizen

my $string = q{ this is a string }; $string = reverse unpack('A*',reverse(unpack 'A*',$string)); print "<$string>\n";