I use it a lot in perlgolf, but not in real code since it tends to destroy the string (notice that your code does, though you tried to avoid that I think). In real code using a
while on a regex in scalar context is slightly faster and not so dangerous. When programming an inner loop and trying to be
blazingly fast, you also should avoid things like $1.$2 since
constructing a new value is a relatively expensive operation
in perl. So the regex variant I'd use is:
But this is still twice as slow as the substr() variant.