use strict; : : Somewhere there is a loop feeding this : and everything gets defined as appropriate. if ( $tally{$country}->{$error}->{$type} ) { $tally{$country}->{$error}->{$type}++; } else { $tally{$country}->{$error}->{$type} = 1; } : : rest of loop : # print our tallies: foreach my $ctry(keys %tally){ foreach my $error(keys %{$tally{$ctry}} { foreach my $type (keys %{$tally{$ctry}->{$error}){ printf "%s,%s,%s = %d\n",$ctry,$error,$type, $tally{$ctry}->{$error}->{$type}; } } }