my %pointdata; my @chunkends; for ( my $i=0; $i<@data; $i++ ) # road-chunks { for ( my $j=0; $j<@{$data[$i]; $j++ ) # points in a chunk { my $key = join(",",$data[$i][$j]->{X},$data[$i][$j]->{Y}); push @{$pointdata{$key}}, sprintf("%5.5d:%5.5d",$i,$j); $chunkends[$i] = $key if ( $j == 0 ); } $chunkends[$i] .= "-$key"; } # Now the %pointdata array contains all the information # about junctures between chunks (these not necessarily # all end-point junctures -- perhaps some road chunks could # intersect at the mid-points?) Also, the @chunkends array # cites the %pointdata keys for the endpoints of each chunk; # if you only want to find end-point junctures, identify the # %pointdata keys with multi-element entries and grep for # each one among the strings in @chunkends.