for ( my $i = 0; $i <= $#array1; $i++ ) { for ( my $j=$i; $j <= $#array2; $j++ ) { # compare $array1[$i] with $array2[$j] ... } }