i would use a different approach and sort the found animals in another hash which is structured in a way, that makes printing easyer
my %animals;
for my $state ( keys %bighash ) {
for my $zoo ( keys %{ $bighash{$state} } ) {
$animals{ $bighash{$state}{$zoo}->[1] }->[0]->{$state}->{$zoo}
+++;
$animals{ $bighash{$state}{$zoo}->[1] }->[1]++;
}
}
for my $animal ( keys %animals ) {
next unless $animals{$animal}->[1] > 1;
for my $state ( keys %{ $animals{$animal}->[0] } ) {
print "$state\n";
for my $zoo ( keys %{ $animals{$animal}->[0]->{$state} } ) {
print "ZOO: $zoo ANIMAL: $animal\n";
}
print "\n";
}
}