my %a1; undef @a1{@a1}; my @in_both = grep { exists $a1{$_} } @a2;