#!/usr/bin/perl use strict; use warnings; my %testData = ( 1900 => 0, 1904 => 1, 1972 => 1, 1973 => 0, 1999 => 0, 2000 => 1, 2001 => 0, 2004 => 1 ); { foreach my $this ( keys %testData ) { if ( $testData{$this} == leapYear($this) ) { print "Correct - $this year " . ( $testData{$this} ? "is" : "is not" ) . " a leap year.\n"; } else { print "Error with $this entry ..\n"; } } } sub leapYear { my $year = shift; if ( $year % 400 ) { if ( $year % 100 ) { # 3. Simple case: it's a leap year if it's divisible by 4 return ( $year % 4 ) ? 0 : 1; } else { # 2. If it's divisible by 100: it's not a leap year. return 0; } } else { # 1. If it's divisible by 400: it's a leap year. return 1; } }