This performs a search and replace on a file as an inplace edit. The search string may be multiple lines long, but must be an exact match - including line end characters. This is not any sort of regex match!
my $matchBlock = do {local $/ = ""; <DATA>};
$/ = $matchBlock;
@ARGV = ("file_to_inplace_edit.txt");
$^I = '.bak';
while (<>)
{
my $matched = chomp;
print $_; #print everything up to the block to be replaced
print "This replaces the matchBlock text\n" if $matched;
}
__DATA__
match string goes here. As long as you like
and spanning lines if you like, but it must
match exactly the text to be replaced including
the line end characters in the file to be edited
must be standard for the OS.
Update: Use chomp per tye's suggestion