my %present; for my $a ( @array1, @array2, @array3 ) { $present{ $a }++ } my @only_two = grep $present{ $_ } == 2, keys %present;