use constant PIE_NO_BACKUP => ''; sub pie(&$@) { ( my $code, # Code ref local $^I, # PIE_NO_BACKUP, '~', '.bak', etc local @ARGV, ) = @_; local *_; # Protect caller's $_. while (<>) { chomp; $code->(); print($_, "\n"); } } # perl -i -pe 's///' file1 file2 pie { s/// } PIE_NO_BACKUP, 'file1', 'file2'; # perl -i.bak -pe 's///' file? data*.txt pie { s/// } '.bak', map { bsd_glob($_) } 'file?', 'data*.txt';