I'm not sure that I completely understand the context of your problem, but a few suggestions. Make a more general expression for the 'NAME: DATE' lines and capture into a hash. You have 4 regex lines to describe the filename, perhaps just one different regex would suffice? When you find the place after the FILENAME where the data capture is supposed to happen, sometimes it works out well to call a subroutine to finish that job off. Here is some code...
#!usr/bin/perl use warnings; use strict; use Data::Dumper; $Data::Dumper::Sortkeys =1; my %hash; sub get_html { while (<DATA>) { if (/<html>/ .. /<\/html>/) ##see [id://525392] { chomp; push @{$hash{DATA}},$_; } } } while (<DATA>) { if ( (my ($name, $date) = m/^\s*([\w ]+):\s+([\w-]+)/)) { $hash{$name}=$date; } if (my ($filename) = m/^\s*<FILENAME>\s*(\w+ex(-)?21.*.htm)/i) { $hash{FILENAME}=$filename; get_html(); } } print Dumper \%hash; =Prints: ********* $VAR1 = { 'CENTRAL INDEX KEY' => '0000786368', 'CONFORMED PERIOD OF REPORT' => '20081231', 'DATA' => [ '<html>', 'blah ', 'smore blah', 'blahblah', ' **** BODY OF TEXT I WISH TO EXTRACT ***** +', '</html>' ], 'DATE AS OF CHANGE' => '20090331', 'FILED AS OF DATE' => '20090331', 'FILENAME' => 'v144610_ex21.htm', 'FORM TYPE' => '10-K' }; =cut __DATA__ *********** Sample text *************** CONFORMED PERIOD OF REPORT: 20081231 &#61663;------ individual +line I want FILED AS OF DATE: 20090331 &#61663;------ individual line I + want DATE AS OF CHANGE: 20090331 &#61663;------ individual line +I want CENTRAL INDEX KEY: 0000786368 &#61663;------ individual line + I want FORM TYPE: 10-K &#61663;------ individual line I want Whole buncha text here ……………. </DOCUMENT> <DOCUMENT> <TYPE>EX-21 <SEQUENCE>7 <FILENAME>v144610_ex21.htm &#61663;-----------My starting point <TEXT> <html> blah smore blah blahblah **** BODY OF TEXT I WISH TO EXTRACT ***** </html> </TEXT> </DOCUMENT> &#61663;----------- My ending point **********End of sample text ***********

In reply to Re: Extract individual lines and block of text from large files by Marshall
in thread Extract individual lines and block of text from large files by wrkrbeee

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.