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


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

I read somewhere (probably in the CookBook) that it's faster to execute this :
$string=~s/^\s+//; $string=~s/\s+$//;
Than the one-liner :

$string =~ s/^\s+|\s+$//g;

Edited by davido: Removed useless use of /g modifier from the two-line (faster) example.