If you'd like to do this in a program, set the $^I variable (same thing as -i on the cmd line) to .bak or whatever. Or don't set it, and you'll just write over the file. Make sure @ARGV is set to the file name(s), either via the cmd line or in the program.