I wouldn't say that using Tie::File is a good advice for
this particular problem. Tie::File is rather heavy-weight,
in resource usage and time needed to learn its API. Tie::File
pays back your investments by giving you some handy functionality, none of which you need for the problem at hand.
It's like suggesting to use XS code to add two numbers. It's
not impossible, it gives you lots of control and flexibility,
but it doesn't make much sense.
This way you can substitute a line i a text file by its number:
use strict ;
my $FILE = "file.txt";
open (FILE, "$FILE");
my @TOTAL = <FILE>;
close FILE;
$TOTAL[1] = "TEST\n";
my $FILE2 = "file2.txt";
open (FILE2, ">>$FILE2");
foreach (@TOTAL) {
print FILE2 "$_";
}
close FILE2;