foreach my $polygon1(@polygon){ foreach my $polygons2(@polygon){ # algorithm checking polygons not merged or overlapped } }