in reply to sorting question
@sorted_xy = sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @xy; [download]
update:
I misinterpreted the structure of $xy; I thought it was a list of coordinate pairs. Use one of the other solutions instead!
Dave.