I know this kind of questions have been asked already many times before. The reason why I come here again is that I feel like I've missed something simple and fundamental.
Is it possible to make this kind of search-replace routine better. For example without opening same file twice. Also speed related advices are welcome.
Please notice that this works with multiline matches and replaces also multiline strings.
#!/bin/perl -w -0777
local $/ = undef;
open INFILE, $full_file_path or die "Could not open file. $!";
$string = <INFILE>;
close INFILE;
$string =~ s/START.*STOP/$replace_string/sm;
open OUTFILE, ">", $full_file_path or die "Could not open file. $!";
print OUTFILE ($string);
close OUTFILE;