use strict; use warnings; use Time::Piece; use feature 'say'; my $date = Time::Piece->strptime( localtime->year() - 4 . " 01 01", "%Y %m %d" ); my $endDate = localtime(); while ( $date <= $endDate ) { say $date; # Get the next first of the month by going to the end of the # month and add one day my $year = $date->year; my $mon = $date->mon; my $day = $date->month_last_day; $date = Time::Piece->strptime( "$year $mon $day", "%Y %m %d" ); $date += Time::Seconds::ONE_DAY; }