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


in reply to How do I remove whitespace at the beginning or end of my string?

Similarly to infinityandbeyond, you could substitute out the leading and trailing white space like this.

$string =~ s/^\s*(.*?)\s*$/$1/;