perlpal's example was $string =~ s/ {1,}/_/g; which matches a space character while your example $string =~ s/\s+/\_/g; uses the whitespace character class (\s) which matches "\t", "\r", "\n" and "\f" as well as the space character. In general, the tr/// operator is more efficient then the s/// operator so I try to use it when appropriate.
In reply to Re^3: Regex operation optimisation
by jwkrahn
in thread Regex operation optimisation
by perlpal
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |