in reply to How to write at immediate next line of detecting a particular pattern

You will read your file line at a time, and write the results to a new file. When you hit your pattern in the input stream, write your 200+line variable. Once this is done you can contiue reading and adding the rest of the original file, either line at a time, or by undefining the input field seperator: $/, as one block. Finally copy the new output file over the original

As the tag <TARGET> looks rather like an XML or HTML like thing, perhaps you should look at proper *ML parsers, to acheive your aim more reliably

When you have some code do post it, and we will be glad to help further

# pseudo code that will not run unless you do some homework... use strict; use warnings; my $big_var = "Some massive\nstring\n"; # that big 200 line var goes h +ere my $pattern = "<TARGET>"; open my $input input file open my $output output file while read line from input { print to output if pattern is matched { print $output $big_var } } close both files copy output over input

PS What will happen if TARGET tag is not on the end of a line?

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!