$SIG{ALRM} = sub { #Your code here }; eval { alarm(60); # Your code will be executed in 60 seconds # do something here # anytime during this 60 sec you can cancel the alarm with alarm(0) };