my @sets = (\@array1, \@array2, ...); for my $i (0..$#sets) { for my $j ($i+1..$#sets) { compute_stuff($sets[$i], $sets[$j]); } }