use strict; use warnings; my @logfile = ( 'Aliens ate my baby-sitter', 'Pearls of Light', 'Really long line of logs', ); my @searchfile = ( 'test these words please', 'ate my', ); my %wordhash; for my $line (@searchfile) { $line = lc $line; # Index the searchlines by their words for my $word (split ' ', $line) { push @{$wordhash{$word}}, \$line; } } LOGLINE: for my $line (@logfile) { my $lower = lc $line; # For every word in the logline, check if we # have a searchline containing that word. for my $word (split ' ', $lower) { for my $searchline (@{$wordhash{$word} || []}) { # If the word was found, compare the lines if (index($lower, $$searchline) >= 0) { next LOGLINE; } } } # If there was no matching searchline, print the logline. print "Processing the log line $line\n"; }