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


in reply to Manipulation of output of multiple parse line.

This article seems to most clearly explain various methods of removing whitespace from the start and end of strings.

If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)