in reply to Re: faster way to grep
in thread faster way to grep

Combining the @ids into a single regex and testing all of them at once is definitely the big win here. The absolute biggest performance gain you can get from the OP's posted code is to fix it so that each file is only read once instead of re-reading it for each id.

If you're dealing with a lot of ids and the single combined regex starts slowing down unacceptably, take a look at Regexp::Assemble for a way of building reasonably efficient regexes which check for a large number of target patterns in one shot. I've used it for up to ~500 target words/phrases at a time and I see no reason why it shouldn't perform well with much larger target sets.