c:\@Work\Perl\monks>perl use strict; use warnings; use autodie; use List::MoreUtils qw(any); # use List::Util in later perl versions my $file1 = \<<"END1"; # strings to be searched for substrings he is man xyzzy don't you what goes on END1 my $file2 = \<<"END2"; # substrings to search for he is what are z try to do END2 open my $fh_substrings, '<', $file2; my @substrings = <$fh_substrings>; chomp @substrings; close $fh_substrings; open my $fh_lines, '<', $file1; while (my $line = <$fh_lines>) { chomp $line; print "'$line' "; my $s; # matched substring in line my $o; # matched substring offset if (any { ($s = $_, $o = index($line, $_)) >= 0 } @substrings) { print "match \n"; print ' ', ' ' x $o, '^' x length $s, "\n"; } else { print "NO match \n"; } } close $fh_lines; __END__ 'he is man' match ^^^^^ 'xyzzy' match ^ 'don't you' NO match 'what goes on' NO match