@ARGV = @files; $^I = '.bak'; while (<>) { # do something with each line of each file # The original line contents is in $_ # print prints to the new version of the file s/foo/bar/g; print; }