sub change_me{ $myvar = somesub(); local $^I = ".bak"; @ARGV = "some_file"; while (<>) { s/foo/$myvar/i; print; } }