There are many ways to do this in Perl. The choice among them depends upon many factors which you did not tell us. How long are the files? Are the <section1> and </section1> tags always on the same line? Is Text2.txt an HTML document? Is it a template that never changes?

One approach that should always work is to slurp Text1 into a single string $string1. Slurp Text2 into $string2. Use a regular expression to replace the gap in $string1 with the contents of $string2. Use positive lookahead and positive lookbehind assertions to match the tags, but not include them in the matched text. (Refer to documentation on extended regular expressions) Good Luck, Bill

Here is a complete perl program that does the substitution that I described in my last post. Note that the /x option allowed me to add whitespace and comments. The /m and /s options are not needed in this simple example. They do no harm in this case and they allow the substitution to work on a multiline string.