in reply to Surprisingly poor regex performance

There is no need to do all this anchoring. ".*" does not match newlines (unless you use the /s option), so the following will also work (and should be just as fast):
my $re = qr/(.*$pat.*)/; while ($mmap =~ m/$re/g) { print $1,"\n"; }

Replies are listed 'Best First'.
Re^2: Surprisingly poor regex performance
by sgifford (Prior) on Dec 14, 2004 at 18:34 UTC
    You're right, that is roughly as fast as /(?:\A|\n)(.*$pat.*\n)/omg. But it's still slower than index/rindex.
      You were asking why the index/rindex is so good. It's because you're matching a pure literal string, which can use the highly-efficient Boyer-Moore search (the longer the literal string, the faster it tends to be).

      For some reason, the "^" is not being optimized properly as an anchor for "/mg" searches. Leaving it out entirely, or substituting the alternate "(?:\A|\n)" pattern, results in searches that are much faster. That seems like a bug in the optimizer.