for my $i (0 .. $#data) { for my $j (0 .. $#data) { next if $i == $j; my @coords_i = @{$data[$i]}[1,2,3]; my @coords_j = @{$data[$j]}[1,2,3]; print OUT "%s to %s Distance-%.5f\n", ####( ; )?? $data[$i][1], $data[$j][1], $data[$i][11], $data[$j][11], distance(\@coords_i, \@coords_j); } }