C:\PERL\bin>perl -le"$SIG{INT}=sub{print 'cleanup';exit 0}; while(1){sleep 1}; END{print 'goodbye'}" # here I hit Control-C cleanup goodbye #### #!/usr/bin/perl use strict; use warnings; my $killed=0; $SIG{INT}=sub{$killed++}; while (1) { # this may take some time sleep 1; last if $killed; } if ($killed) { print "cleaning up after getting a sig int\n" }else{ print "finished infinite loop, halting problem next\n" }