Here are couple of ways to solve this:
This first method is a way to do this without having to have a flag that indicates "inside the record".
#!/usr/bin/perl use strict; use warnings; while (<DATA>) { process_record($_) if /^Success\|Filter passed/; } sub process_record { my $trigger_line = shift; print "$trigger_line"; print while (defined ($_ = <DATA>) and $_ =~ /\S/); print "\n"; } __DATA__ Success|Filter passed|[invalid field]|[invalid field]|Id-350a875b08796 +5e58cbe1f4a Accept: text/plain, text/plain, application/json, application/*+json, +*/*, */* Host: api2.tim.com.br User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.3 +6 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Via: 1.1 X-Forwarded-For: 144.22.98.123 X-Forwarded-Host: X-Forwarded-Server: Success|Success in calling policy shortcut|[invalid field]|[invalid fi +eld]|[invalid field]|Id-350a875b087965e58cbe1f4a|Call 'Set Request Me +ssage'|GET Accept: text/plain, text/plain, application/json, application/*+json, +*/*, */* Host: api2.tim.com.br User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.3 +6 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Via: 1.1 api2.tim.com.br X-Forwarded-For: 144.22.98.123 X-Forwarded-Host: X-Forwarded-Server: Content-Type: text/xml; charset="UTF-8" Success|Filter passed|[invalid field]|[invalid field]|Id-350a875b08796 +5e58cbe1f4a Accept: text/plain, text/plain, application/json, application/*+json, +*/*, */* Host: api2.tim.com.br User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.3 +6 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Via: 1.1 X-Forwarded-For: 144.22.98.123 X-Forwarded-Host: X-Forwarded-Server:
Another way...
Perl has a special operator that will keep track of the "inside the record" flag for you..
#see https://www.perlmonks.org/?node_id=525392 while (<DATA>) { print if (/^Success\|Filter passed/ ... /^\s*$/); }

In reply to Re: Search after match in dynamic lines by Marshall
in thread Search after match in dynamic lines by leoberbert

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.