for (my $num = $members) { foreach $month2 (@calendar) { foreach $name2 (@members) { if ($hoursWorked{$name2}{$month2} == 0) { $num--; #this is to protect against false averages, because $members will usually have a value of 13, but I don't want to count the zero values because is would result in an incorrect average, (i.e. 24/6 instead of 24/13 because only 6 people worked)