sub inplace{ my @files = @_; local($^I, @ARGV)=(".bak", $file); # Now i can use <> local $SIG{__WARN__} = sub{ ## Handle open errors here }; while(<>){ local $SIG{__WARN__}; # disable it for loop body # do stuff on $_ print; } }