#!/usr/bin/perl # http://perlmonks.org/?node_id=1145607 use File::Slurp; use strict; use warnings; my $f1 = shift; my $f2 = shift; my (%hash1, %hash2); $hash1{$_} = 1 for lc(read_file $f1) =~ /[A-Za-z0-9]+/g; $hash2{$_} = 1 for lc(read_file $f2) =~ /[A-Za-z0-9]+/g; my $count = my @common = sort grep $hash2{$_}, keys %hash1; print "count: $count\n@common\n";