use Time::Local qw( timelocal_nocheck ); my @time_data; @time_data = localtime(); $time_data[4]++; # Next month. $time_data[3] = 0; # Last day of previous month. @time_data = localtime(timelocal_nocheck(@time_data)); my $year = $time_data[5]+1900; my $month = $time_data[4]+1; # Make 1-based my $last_day = $time_data[3]; printf("The last day of this month (%04d/%02d) is %d.\n", $year, $month, $last_day ); __END__ output ====== The last day of this month (2005/01) is 31. #### 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.