welcome to the monastery umaykulsum,

you put some effort formatting your questio and showing your attempt, but if i can ask for more, try to show some simplified data; infact having AAAA and ABAA instead of 160 chars line is the same problem.

That said, i notice a first error: you are, for each file to read, reopening also the output one using the mode > which will overwrite the file each time. Put the opening of the output file outside of the loop. Also Perl is smart enought to close filehandels for you (wwhen they go outside of a scope) but is better check the open and close filehandles explicitly. Second you are setting $/ to null enabling the so called slurp mode. Doing you influence what Perl see as line, becoming different from what you call a line.

Finally perhaps i dont understand your question clearly: why you want 4 lines to be printed? why the paragraphs which second line starts with TACAG must be associated to the (header?) line that contains 20279 and not with the one containing 18609 ?

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: count the occurrence of second line of a paragraph in a file by Discipulus
in thread count the occurrence of second line of a paragraph in a file by umaykulsum

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.