in reply to timer in perl

before the loop

 $start = time;

at the end of the loop

last if time > $start + $duration;

(untested)

OR

 while ( time < $start + $duration)

instead of an endless loop.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Wikisyntax for the Monastery