my $error; sub timeout { ... if( $error ) ... ... } ... $SIG{ALRM} = \&timeout;