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


in reply to How can I strip an arbitary number of leading spaces from a string?

Use a regex with a quantifier. Use this one if you're not sure there will be any spaces at the start of the string:

$string =~ s/^\s*//;

Use this one if you know there will be at least one:

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

{QA Editors note: As japhy pointed out, the "+" quantifier is preferable over the "*" quantifier, even if it's unknown whether the string being tested has leading whitespace or not. With s/^\s+//;, strings lacking leading whitespace simply will be passed over. Furthermore, the "+" quantifier is faster than the "*" quantifier.}