in reply to
inline file modification
Look at the Tie::File module. It allows you to edit a file in-place as if it were an array.
This example replaces any line containing $idtag with a line containing $replacement.
use Tie::File;
my $file = 'filename';
my @tied_file;
my $idtag = 'idTag';
my $replacement = 'replacement line';
# Create the array @tied_file from $file
tie(@tied_file, 'Tie::File', $file);
# Preserve the index so we can work directly on lines of @tied_file
foreach my $i (0 .. $#tied_file) {
if ($tied_file[$i] =~ /$idtag/) {
# Do something to this line of @tied_file
$tied_file[$i] = $replacement;
}
}
untie(@tied_file);