use warnings; use strict; use DateTime; my $now = DateTime->now; my $start = DateTime->new( year=>$now->year-4 ); my $end = $now; my $dt = $start->clone; $dt->truncate(to=>'month')->add(months=>1) if $dt->day!=1; for ( ; $dt<$end; $dt->add(months=>1) ) { print $dt->ymd, "\n"; }