use threads; # interrupt thread sub handler { while (1) { XS_wait_for_interrupt(); print "got interrupt\n"; } } threads->new(\&handler)->detach(); # main thread my $continue = 1; $SIG{INT} = sub { $continue = 0; }; while ($continue){ ...do_work...; }