my $file = '/foo/file.txt'; open IN, $file or die "Can't read $file perl says $!\n"; my @lines = ; close IN; for my $line (@lines) { # do stuff with the lines } # rewrite the file in its entirity open OUT, '>$file' or die "Can't write $file perl says $!\n"; print OUT $line[0]; # print out the first line from the old file print OUT @other_stuff; # print whatever else you want close OUT;