my $first = time; while (1) { # Do stuff here; my $next = int((time - $first + 3599)/3600) * 3600; sleep ($first + $next - time); }