You are not handling Leap Years correctly. I'd check CPAN. There are a dozen or modules that handle dates in including Date::Calc.
UPDATE: I see jryan has pointed this out also. There is also Date-LeapyearFYI:The rules for Leap Year are:
Every year divisible by 4 is a leap year.
But every year divisible by 100 is NOT a leap year
Unless the the year is also divisible by 400, then it is still a leap year.
grep