use strict; my %hash; my @ary1 = qw(1 2 3 4 5); my @ary2 = qw(6 7 8 1 2); foreach (@ary1, @ary2){ $hash{$_}++; } foreach my $key (keys %hash){ print "$key showed up $hash{$key} times\n" if $hash{$key} != 1; }