# Turn at least one of the arrays into a hash (hashes are perfect for this kind of thing) @Hash1{"A", "B", "C", "D"} = undef; # Then, just use exists... print scalar grep {exists $Hash1{$_}} ("J", "C", "T", "A");