@dist = map sqrt($x[$_]**2+$y[$_]**2+$z[$_]**2), 0..$#x; #### @dist = map sqrt(($x[$_]-$x0)**2+($y[$_]-$y0)**2+($z[$_]-$z0)**2), 0..$#x; #### @indices = sort {$dist[$a]<=>$dist[$b]} 0..$#dist; @dist = @dist[@indices]; @x = @x[@indices]; @y = @y[@indices]; @z = @z[@indices]; @name = @name[@incides]; #### for my $one (0..$#@dist-1) { my $two = $one; while (++$two < @dist && $dist[$two]-$dist[$one] <= $cutoff) { print "found pair: ($x[$one],$y[$one],$z[$one]) and ($x[$two],$y[$two],$z[$two])\n" if sqrt(($x[$one]-$x[$two])**2+($y[$one]-$y[$two])**2+($z[$one]-$z[$two])**2) <= $cutoff; } }