http://qs321.pair.com?node_id=1175730


in reply to How to Run a section of code for a particular amount of time ?

Measure the time spent in the loop and create an additional exit condition. As the main time in your loop is spent sleeping for one second, you may as well count how often the loop has been executed, as shown below

HTH, Rata

my $count = 0; until((@window3=FindWindowLike(undef,"calculator")) || ($count > 29)) { print("\ncan't find window\n"); sleep 1; $count ++; }