in reply to Re^2: Declaring variables recursively
in thread Declaring variables recursively

There are data structures well-suited to sorting two-dimensional points, and some have been implemented in perl. Check out Algorithm::QuadTree for example.

For a contouring implementation PDL::Graphics::TriD::Contours might be worth a look.