I expect an improvement if you just add a common lookahead:
but I have no way to test it without your data file.$filter = qr/(?=[08])(?:00901808|87654321)/;
See also the modules Regex::PreSuf, Regexp::List and Regexp::Assemble for simpler solutions, as they can build a (hopefully) more efficient regex for you.
p.s. I just found this blog post about just this situation.
Alternation is usually slow in Perl because the engine has to backtrack when trying each alternative. It's much faster to give perl a character sieve up front, e.g. (?=cdb) and then factor out common prefixes and suffixes. The problem is that when you have a ton of alternatives, doing all this is a pain and it decreases readability to almost zero. Which is why I had avoided it to date...
In reply to Re: Unefficient Regexp 'Matching this or that'
by bart
in thread Unefficient Regexp 'Matching this or that'
by pelagic
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |