local $SIG{ALRM} = sub { die "timeout" }; eval { alarm(12); require './main.pl'; &generate_page; alarm(0); }; if ($@) { if ( $@ =~ /timeout/ ) { croak "TIMEOUT: $@"; } else { alarm(0); # clear the still-pending alarm die "$@"; } }