my $f1 = shift; my $f2 = shift; if (! defined($f1) or ! defined($f2)) { die "Need two text file names as arguments. \n"; } my %results; open my $file1, '<', $f1; while (my $line = <$file1>) { $line =~ s/[[:punct:]]//g; for my $word (split(/\s+/,$line)) { $word =~ s/[^A-Za-z0-9]//g; $results{lc $word} = 1; } } my @words2; my @storage; open my $file2, '<', $f2; while (my $line = <$file2>) { $line =~ s/[[:punct:]]/ /g; @words2 = grep { /\S/ } split(/ /,$line); for (my $i=0; $i $results{$a} } keys %results) { if ($results{$words} > 1){ $counter = $counter+1; print $words, "\n\n" ; } } printf "Found %1.0f words in common\n", $counter;