my $num_ctrlc = 0; $SIG{'INT'} = sub { $num_ctrlc++; print "Got $num_ctrlc ctrl-c\n"; exit if $num_ctrlc > 2; }; # rest of program