For starters, what does "closed...no comment" in your "Update" mean? Did you despair of getting code to do the specific job? Did you find an answer that led you in the right direction? or something else?

Then, please clarify what your sample output is telling us: on first reading I thought you wanted one output file with all the material except the "start" lines... but, on rereading, the phrase "inside a text file 2. and so on" (belatedly) caught my eye, making me wonder if you wanted each instance of the boldfaced material to go in a separate file (and no, I didn't bother to try to answer that question by studying the code you posted: it's not easily readable and less than readily comprehensible for reasons outlined by others).

But, the Perl slogan "There is more than one way to do it" (aka TIMTOWTDI or TIMTOADY, etc)" is definitely a truism for your problem, however one is supposed to understand your question.

and there are more.

This site, including Super Search and Tutorials can help you get started with Perl (yes, I suspect the reply code is cargo-culted from somewhere without much understanding). So too can numerous on-line tutorials (for example, those at http://learn.perl.org/) but search this site a bid to see which are well-regarded and which are trash) and, finally, being very much "old-school," I also suggest ( tada!! ) "books" such as Learning Perl.

Addendum:

Your title, if carefully chosen, suggests you are thinking of the "this is a example \d line" as the "similar patterns," perhaps because those are what you want to capture. But for your purposes, think instead of what you want to discard; instances of "stop" (with or without blank lines preceding).

It's easy enough to write a regex to deal with the "this is..." lines -- matching on any digit and capturing work just fine (when the regex is constructed correctly), but there's a lot less opportunity for error (in your example data) to match on the four letter word, "stop."


In reply to Re: extraction of text between 2 similar patterns in a text file by ww
in thread extraction of text between 2 similar patterns in a text file by seek_m

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.