use DateTime; my $now = DateTime->now; for ( my $dt = $now->clone->truncate(to=>'month') ->subtract(years=>2)->add(months=>1); $dt < $now; $dt->add(months=>1) ) { my $last = DateTime->last_day_of_month(year=>$dt->year, month=>$dt->month,time_zone=>$dt->time_zone); print $dt->ymd," to ",$last->ymd,"\n"; } __END__ 2015-07-01 to 2015-07-31 2015-08-01 to 2015-08-31 2015-09-01 to 2015-09-30 ...