my $count = 0; $SIG{INT} = sub { print "\nCaught an interrupt\n"; exit if $count++ > 2 }; $|++; while (1) {print '.'; sleep 1}