http://www.perlmonks.org?node_id=165583


in reply to Count of words that match in an array

use strict; my @Array1 = ("A", "B", "C", "D"); my @Array2 = ("J", "C", "T", "A"); my %seen = (); foreach (@Array1) { $seen{$_}++ }; my $count = 0; foreach (@Array2) { exists $seen{$_} and $count++; } print "Number of duplicates: $count\n";