my $stop = 0; $SIG{whatever} = sub {$stop = 1 }; while(@stack and !$stop) { process(shift @stack); ... }