{ local @ARGV = 'not_a_file'; local $SIG{__WARN__} = sub { die shift }; # SIG{__WARN__} is now set INSIDE the while loop # also, so you might want to unset it locally there while (<>) { print "This won't print\n"; } print "This won't print either\n"; }