Coming up with the "best" solution depends a lot
on variables like how large the files are, what
kind of performance you need, and how you'll come
up with the new file name. However, here's the
simplest way of solving that (if memory usage and
time are no issues).
use strict;
local $/ = undef; # grab everything from file
open FILE, "my_file" or die $!;
foreach $data_block (split /match_instance/, <FILE>) {
open OUTPUT, "new_file_name" or next;
print OUTPUT $data_block;
close OUTPUT;
}
Note that whatever string we look for ("match_instance"
in this example) will get deleted by the nature of split.
You can enclose
match_instance in parenthesis
if you want it included. But then you'll end up with some
array that looks like
"match_instance", "data", "match_instance", "more data", etc. So you couldn't use a foreach to
process it.
-Ted