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


in reply to Re^3: How do I quickly strip blank space from the beginning/end of a string?
in thread How do I quickly strip blank space from the beginning/end of a string?

Good point. I've tried the 3 methods below:
if ($x =~ /\s/)
and
if (substr($x, -1) =~ /^\s/
and
if (rindex($x," ") == 0 || rindex($x,"\r") == 0 || rindex($x,"\n") == + 0 || rindex($x,"\t") == 0)
The rindex method is much faster on the data that has spaces; otherwise the substr method is the fastest. Any other good ideas, keeping in mind that the data (I think) won't often contain any trailing spaces?