while (defined (my $key = each %SIG)){ my $foo = $key; # for closures $SIG{$foo} = sub { print "I am SIG$foo\n" }; }