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


in reply to Optimizing a regex that replaces near the end of a string

Another technique I've used with some success is simply calling reverse() on the string, running the regex, and then reversing again. You'll want to benchmark against your typical input, of course.
  • Comment on Re: Optimizing a regex that replaces near the end of a string