use Time::Local qw( timegm_nocheck ); my $year = 2005; for my $month (1..12) { my $last_day = (gmtime(timegm_nocheck( 0, 0, 0, 1-1, # Last day of previous month. $month-1+1, # Next month (0-based). $year )))[3]; printf("The last day of %04d/%02d is %d.\n", $year, $month, $last_day ); } __END__ output ====== The last day of 2005/01 is 31. The last day of 2005/02 is 28. The last day of 2005/03 is 31. The last day of 2005/04 is 30. The last day of 2005/05 is 31. The last day of 2005/06 is 30. The last day of 2005/07 is 31. The last day of 2005/08 is 31. The last day of 2005/09 is 30. The last day of 2005/10 is 31. The last day of 2005/11 is 30. The last day of 2005/12 is 31.