my $johndoe_hours = 0; foreach my $month ( keys %main } { if ( exists $main{$month}{johndoe} ) { $johndoe_hours += $main{$month}{johndoe}; } }