sub leapYear { my $year = shift; if ( $year % 400 == 0 ) { # 1. If it's divisible by 400: it's a leap year. return 1; } else { if ( $year % 100 == 0 ) { # 2. If it's divisible by 100: it's not a leap year. return 0; } else { # 3. Simple case: it's a leap year if it's divisible by 4 return ( $year % 4 ) ? 0 : 1; } } }