BEGIN { # allow script to be reinitialized with a HUP signal $SIG{HUP} = sub { $HUP = 1; warn "Caught HUP\n" }; } # main loop while ( 1 ) { $conn = accept_new_conn(); # check if we have been HUPPED if ( $HUP ) { REHUP: # reset the flag $HUP = 0; warn "***** Widget reinitializing\n"; do_disconnect(); do_init(); # now it is possible, but unlikely that we get another SIG HUP while # we are performing our reinit routines so we need to redo this # stuff if that occurs, otherwise we will be partially reinitialised goto REHUP if $HUP; } # more code here }