If your file is small enough (no more than several hundred meg and guaranteed not to grow beyond that size), slurping and searching the entire file may be useful. Code:

use warnings; use strict; my $doc = do { local $/; <DATA>; }; # slurp entire file # print "<<<$doc>>> \n"; # FOR DEBUG my $rx_account = qr{ (?<! \d) \d{12} (?! \d) }xms; my $rx_amount = qr{ (?<! \d) \d+ [.] \d\d (?! \d) }xms; my ($two_lines, $account, $amount) = $doc =~ m{ ( ^ ACCOUNT \s+ NUMBER \s+ ($rx_account) .*? ^ YOUR \s+ LOAN \s+ PAYMENT .*? ($rx_amount) ) }xms; print "two lines: <<<$two_lines>>> \n\n"; print "account '$account' amount '$amount' \n"; __DATA__ ACCOUNT NUMBER 000111111111 YOUR LOAN PAYMENT FOR THE YEAR WILL BE 00.00 OF WHICH 00.00 WILL BE FOR PRINCIPAL AND INTEREST, 00.00 WILL GO ESCROW ACCOUNT, AND .00 WILL BE FOR DISCRETIONARY ITEMS THAT YOU CHOSE TO BE INCLUDED WITH YOUR LOAN PAYMENT. THE EFFECTIVE DATE OF YOUR NEW SCHEDULED PAYMENT IS 00/00/00.
Output:
c:\@Work\Perl\monks\crusty_collins>perl match_multiline_1.pl two lines: <<<ACCOUNT NUMBER 000111111111 YOUR LOAN PAYMENT FOR THE YEAR WILL BE 00.00>>> account '000111111111' amount '00.00'

Updates:

  1. See also File::Slurp and friends.
  2. What you have shown in the OP is not what I would think of as a "paragraph" match, but rather a multi-line match. It's difficult to see from the given data just what a paragraph would be.


Give a man a fish:  <%-(-(-(-<


In reply to Re: regex : get a paragraph, not just line by AnomalousMonk
in thread regex : get a paragraph, not just line by crusty_collins

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.