in reply to searching polygons not merged
but that example performance is really bad
This will run in less than half the time:
while (my $polygon1 = shift @polygon) { foreach my $polygons2(@polygon){ # Comparison code here } }
Additionally, I'd probably create an array of the smallest circles which enclose all the vertices of each polygon before starting the main loop. If the two circles don't overlap (an easy calc) then the two polygons won't either. That will reduce the number of more expensive calcs required.
In Section
Seekers of Perl Wisdom