my %hash; foreach my $i ( 0..$#array ) { foreach my $j ( @{ $array[ $i ] } ) { $hash{ $j } ||= []; #need to set this if not made if ( ! grep { $i == $_ } @{ $hash{ $j } } ) { push @{ $hash{ $j } }, $i; } } } my @matches = grep { @{ $hash{ $_ } } > 1 } keys %hash;