Can you give an example file that you parse? I would say you could just change the input record separator to paragraph mode eg  local $/ = ""; when you find "set private-key ", then read one more time with <DATA>. I am not sure if enc data ends with '[...]' or "\n\n" or '"' or what.

please post an example file.
#here is a small test i did with the examples given in OP use strict; use warnings; while(<DATA>){ if ( /set private-key/){ print "\nsetting input seperator to paragraph mode\n"; local $/ = ""; #record separator will change itself back to de +fault AFTER leaving the if block print "skipping encrypted data\n"; <DATA>; print "encrypted data skipped and should not be printed !\n\n" +; next; } print if /\w+/; } __DATA__ random data more random data blah blah one last test BEFORE! encrypted data! set private-key "-----BEGIN ENCRYPTED PRIVATE KEY----- sdfkjghsdlkhfgldkfjghldkfjgh sdflkjgdfgl;kd;lfkgjdlfkgjd;l dlkjfghlkdfjghldskfjhgldskfjhg this is AFTER encrypted data more rand0m data this is the last test AFTER! encrypted data.
The idea here is to read the file/s one line at a time until you find the desired string. then once you find that string, change the input record separator to stop at the end of the enc data (if possible). if enc data is always the same length, then you could find the desired string and then read that static length every time.
EDIT: Cleaned up post... a little.

In reply to Re: regex for identifying encrypted text by james28909
in thread regex for identifying encrypted text by skendric

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.