my %table; # The number of items of group $d of length N (where N is 1 to a # max. length determined elsewhere) found in $b. for my $file (keys %a) { for my $group (keys %{$a{$file}}) { for my $subgroup (keys %{$a{$file}{$group}}) { for my $length (@{$a{$file}{$group}{$subgroup}}) { $table{$file}{$subgroup}[$length]++; } } } }