$SIG{ALRM} = sub { report(); exit }; alarm(86400 * 3); # your test code here ... # at the end, print report report(); sub report { # your reporting code }