my @months = qw{ May Jun }; my @end_of_month = ( 31, 30 ); my $start_day = 16; my $end_day = 3; my $end_month = $months[1]; my $incr = date_initialize( $start_day, \@months, \@end_of_month); for ( my ($day, $month) = ( 16, "May") ; $day != $end_day or $month ne $end_month ; ( $day, $month ) = $incr->() ) { # # do stuff # } # # set up incrementer. This function returns a reference to an indexing function. # sub date_initialize { my $day = shift; my $monthref = shift; my $endmonthref = shift; my $month_index = 0; return sub { $day++; if ( $day > $$endmonthref[$month_index] ) { $day = 1; $month_index++; } return ( $day, $$monthref[$month_index] ); } }