#!/usr/bin/perl my $interrupted; local $SIG{INT} = sub { $interupted = 1 }; while (1) { print "hi\n"; sleep 1; if ($interrupted) { warn "ctrl-c pressed!\n" and $interrupted = 0 } }