It's clear that you want to find nearby points in a 2-dimensional space. One effective way is to overlay a grid which groups the data into cells. Then you only have to compare points from adjacent cells.
Some pseudo-code:
my %CellMembers;
for my $i (0..$npoints) {
my $cellid = int($lat[$i]).",".int($long[$i]);
push(@{$CellMembers{$cellid}}, $i);
}
# iterate over cells
for my $ci (keys %CellMembers) {
for my $cj (...cells within distance 1 of $ci...) {
for my $i (@{$CellMembers{$ci}}) {
for my $j (@{$CellMembers{$cj}} {
...compare points $i and $j...
}
}
}
}
Lots of nested loops, but probably a big time saver.