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