in reply to how to sleep-awake on perl script?

Usually I do this by having my code into a loop, check for an event and terminate the loop if wanted to. Maybe someone has better way. I am looking forward to a reply too ! This should work through SSH too !
$flag=1; while($flag) { $sleep=checkEvent(); if(not $sleep) { --- do events $flag=0; } else { #whatever time you want to delay before checking again ! sleep(2); } }