Umm.. if you leave the if at the bottom outside the while the next is useless, and any $@ values will cause the loop to continue, including non-timeout values. You could possibly also miss valid die messages. To be really useful you should probably check the $@ at the end of the eval after the alarm(0);