in reply to Compile the regex
in thread speeding up regex

Compiling keywords can make a difference if you do all of them at once, before the loop.

#!/usr/bin/perl -w use strict; open WORDS, "<kwords" or die; my %kwords=(); while (<WORDS>) { chomp; $kwords{$_} = qr/\b$_\b/m; } close WORDS; my %found =(); for my $f (<abstract*>) { local $/; open FILE, $f or die "$f\n"; my $text = <FILE>; close FILE; for (keys %kwords) { my $val = $kwords{$_}; $found{$f} .= "$_ " if $text =~ /$val/; } } print "$_\t$found{$_}\n" for sort keys %found;

Assuming that the keywords are in a file, and each abstract is in a separate file, precompilation makes the search 30% faster (using 1000 test files, 300 words each, 3 random keywords in 2/3 of them).