If your files are small, then slurping and using a regex with /s and a lookahead is the easiest way:

#! perl -slw use strict; my $data = do{ local $/; <DATA> }; print "'$1'$2'\n" while $data =~ m[([a-z-]+):(.*?)\n(?=[a-z-]+:|$)]sg; __DATA__ aut-num: AS19710 as-name: ASN descr: S4R admin-c: SNE1 tech-c: SNE1 import: from AS3356 63.215.71.1 at 63.215.71.2 action pref=20; +med=50; from AS3356 63.215.86.133 at 63.215.86.134 action pref= +50; med=150; accept ANY import: from AS3847 action pref=10; accept ANY export: to AS3847 announce AS19710 export: to AS3356 announce AS19710 notify: nwcontact@email mnt-by: S4R changed: andy@email 20010502 source: LEV

At each iteration of the while loop, $1 will be the section header, and $2 the body of the section with all the whitespace intact. You can further process $2 to remove or reduce the whitespace as required.

P:\test>448390 'aut-num' AS19710' 'as-name' ASN' 'descr' S4R' 'admin-c' SNE1' 'tech-c' SNE1' 'import' from AS3356 63.215.71.1 at 63.215.71.2 action pref=20; + med=50; from AS3356 63.215.86.133 at 63.215.86.134 action pref= +50; med=150; accept ANY' 'import' from AS3847 action pref=10; accept ANY' 'export' to AS3847 announce AS19710' 'export' to AS3356 announce AS19710' 'notify' nwcontact@email' 'mnt-by' S4R' 'changed' andy@email 20010502' 'source' LEV'

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco.
Rule 1 has a caveat! -- Who broke the cabal?

In reply to Re: Best way to parse multiline data? by BrowserUk
in thread Best way to parse multiline data? by jalewis2

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.