http://qs321.pair.com?node_id=90067


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

Try this, it's a little different, though it only works on leading whitespace:
s/\G //g
<paraphrase> It uses the \G anchor with the /g flag to start where the previous match left off, replacing spaces with nothing as it goes along. </paraphrase>

It's from p. 245 of Effective Perl Programming by Joseph N. Hall and Randal Schwartz (merlyn). Randal, if there's a problem with me quoting this stuff, just let me know.