How can I use Perl's "-i" option from within a program? "-i" sets the value of Perl's $^I variable, which in turn affects the behavior of "<>"; see perlrun for more details. By modifying the appropriate variables directly, you can get the same behavior within a larger program. For example: # ... { local($^I, @ARGV) = ('.orig', glob("*.c")); while (<>) { if ($. == 1) { print "This line should appear at the top of each file\n"; } s/\b(p)earl\b/${1}erl/i; # Correct typos, preserving case print; close ARGV if eof; # Reset $. } } # $^I and @ARGV return to their old values here This block modifies all the ".c" files in the current directory, leaving a backup of the original data from each file in a new ".c.orig" file.