use POSIX qw( strftime ); sub next_day { my $start_d = (localtime)[3]; for (;;) { sleep(30*60); my $d = (localtime)[3]; return if $d != $start_d; } } next_day() for 1..5; print strftime("%Y-%m-%d\n", localtime()); next_day() for 1..4; print strftime("%Y-%m-%d\n", localtime());