use strict; my $hit_count = 0; $SIG{INT} = sub { if (++$hit_count > 3) { print "terminated!\n"; exit; } print "Hit!\n"; }; while (1) { sleep(1000); }