in reply to Re: Efficient regex matching with qr//; Can I do better?
in thread Efficient regex matching with qr//; Can I do better?

Since the if block is only entered about 20000 times, changes there aren't likely to make a big difference.

But yes, seeing what kind of patterns these are would provide some clues. If they are literal strings, for instance, it may be better to not do the qr// but instead do

if (0 <= index($text, $pattern) && $text =~ /\b$pattern\b/) { }
(the latter bit just to preserve the \b checks).

Replies are listed 'Best First'.
Re^3: Efficient regex matching with qr//; Can I do better?
by ikegami (Patriarch) on Jul 11, 2008 at 06:15 UTC
    From what I understand, a compiled regexp is just as fast as index for literal strings.