Perl signal handlers are reset in END blocks
问题 This works as expected since Perl 5.10.1: SIGINTs are trapped. #!/usr/bin/perl use strict; use warnings; $SIG{INT} = sub { die "Caught a sigint $!" }; sleep(20); But here SIGINTs are not trapped. #!/usr/bin/perl use strict; use warnings; $SIG{INT} = sub { die "Caught a sigint $!" }; END { sleep(20); } This can be fixed by setting the handler again in the END block, like so: END { $SIG{INT} = sub { die "Caught a sigint $!" }; sleep(20); } But that won't work if you have more than one block: