my %a2hash; $a2hash{$_}++ for ( @array2 ); for ( @array1 ) { if ( exists( $a2hash{$_} )) { # use the value that matched, and number of matches in @array2: do_something( $_, $a2hash{$_} ); } }