my @file = ; my @array = ('file', 'this', 'dog', 'forward'); my $superterm = join '|', @array; my @stringsfound; my %guard; for (@file) { while ($superterm ne '' and /($superterm)/gi) { print "Found <$1>\n"; # To watch it work push @stringsfound, $1; $guard{$1} = undef; $superterm = join '|', grep {!exists $guard{$_}} @array; } } print map "$_\n", @stringsfound; __DATA__ No one could find this dog dog dog a young boy came forward to claim this file but his file was a mile long