use warnings; use strict; my @files = ; for my $modfile (@files) { # read open my $ifh, '<', $modfile or die "$modfile: $!"; my $data = do { local $/; <$ifh> }; # slurp close $ifh; # modify $data =~ s/Marry Had A\nLittle Lamb\nShe Was GOOD\n/CHANGED!!!\n/smg; # write open my $ofh, '>', $modfile or die "$modfile: $!"; print $ofh $data; close $ofh; } #### use warnings; use strict; use Path::Tiny; my @files = path(".")->children(qr/^Test.*_Copy$/); for my $modfile (@files) { $modfile->edit(sub { s/Marry Had A\nLittle Lamb\nShe Was GOOD\n/CHANGED!!!\n/smg; }); } #### perl -wMstrict -0777 -i -pe 's/Marry Had A\nLittle Lamb\nShe Was GOOD\n/CHANGED!!!\n/smg' Test*_Copy #### use warnings; use strict; use File::Replace 'replace3'; my @files = ; for my $modfile (@files) { my ($infh,$outfh,$repl) = replace3($modfile); my $data = do { local $/; <$infh> }; $data =~ s/Marry Had A\nLittle Lamb\nShe Was GOOD\n/CHANGED!!!\n/smg; print $outfh $data; $repl->finish; } #### use warnings; use strict; my @files = ; for my $modfile (@files) { open my $fh, '+<', $modfile or die "$modfile: $!"; my $data = do { local $/; <$fh> }; $data =~ s/Marry Had A\nLittle Lamb\nShe Was GOOD\n/CHANGED!!!\n/smg; seek $fh, 0, 0 or die $!; truncate $fh, 0 or die $!; print $fh $data; close $fh; }