sub callfc() { # just keep printing until the signal goes off for ($i = 0; $i < 1000; $i++) { print "$i \n"; sleep(1); } } for ($j = 0; $j < 1000000; $j++) { # set signal time out alarm(2); # set up signal handler $SIG{ALRM} = sub { goto "LABEL"; }; # call the function &callfc(); LABEL: # hopefully skip to the next iteration of the loop } print "I am continuing with the code\n"; sleep(1); print "I am continuing with the code\n";