sub days_in_month { my $month = shift; my $year = shift; my @mdays = qw( 31 28 31 30 31 30 31 31 30 31 30 31 ); if ($month == 2) { if ($year % 4 == 0) { # normal leap year if ($year % 100 == 0) { # century year, not a leap year return 28 unless ($year % 400 == 0); # century AND leap year } return 29; } } return $mdays[$month - 1]; # fudge the index }