# put this in a block so that the changes to global variables
# don't affect other bits of my program
{
# load the filename into @ARGV so it can be edited in-place
local @ARGV = ( $file );
# turn on in-place editing, without keeping a backup
# to keep a backup, use: local $^I = '~';
local $^I = '';
# loop through all lines in the file
while(<>) {
# current line is stored in $_
# anything you print will be printed to the file instead of the current line
# this just prints the current line, so the file doesn't change
print;
}
}