#!/usr/bin/perl use strict; use warnings; my $file1Content = <) { my @words = map {lc} grep {$_} split /[\W\d]+/, $line; $group1{$_} = $_ for @words; } my %common; open my $file2, '<', \$file2Content; while (my $line = <$file2>) { my @words = map {lc} grep {/\S/} split /[\W\d]+/, $line; $common{$_} = $_ for grep {exists $group1{$_}} @words; } print "$_\n\n" for sort values %common; printf "Found %1.0f words in common\n", scalar keys %common;