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


in reply to Pattern matching across two files, Need something better than grep -f!

I have tried using grep -f, but it is taking a very long time to do this job
grep is optimized to do one job well. Unless you can make shortcuts because you know something special about the input which you can use, it's likely that any Perl solution isn't going to beat the grep one.

For instance, if the blocks of 18000 lines which share the first "token" are in the same order as the entries in pattern.txt, you can use this fact and make a much faster solution than just trying to match every line with every other.