in reply to Grep hash of hashes

Do you only want to see the counts? I guess not, you also want to see the number and colour to which the count belongs.

BTW, the main point of $_ is you don't have to write it. If there's no assingment in a my statement, there's no need to undef it.

#!/usr/bin/perl use warnings; use strict; my %hash; <DATA>; # Skip the header. while (<DATA>) { my ($name, $number, $color) = split; $hash{$name}{$number}{$color}++; } my %returnedHash = %{ $hash{GNAEUS} }; for my $number (keys %returnedHash) { for my $color (keys %{ $returnedHash{$number} }) { print "$number $color $returnedHash{$number}{$color}\n"; } } __DATA__ NAME NUMBER COLOR GNAEUS 1 BLUE GNAEUS 1 RED GNAEUS 3 MAGENTA GNAEUS 3 GREEN GNAEUS 3 GREEN FABIUS 1 BLUE FABIUS 2 YELLOW FABIUS 1 RED
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ