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!

In reply to Re: How to write at immediate next line of detecting a particular pattern by Random_Walk
in thread How to write at immediate next line of detecting a particular pattern by Dravidan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.