I don't know if this will work for what you want (and it may not be the best solution, so I pray other, wiser monks will comment, so we both may learn), but this is how I have handled it in the past (with __DATA__ for testing, fields named as they were so I could verify the results quickly visually). Good luck in finding a solution.
#!/usr/bin/perl -w use strict; use warnings; my $multiline_seperator = "\n"; my ($fieldname, $fieldvalue, $line, %pkg); while ($line = <DATA>) { # Lines following empty/space/astrisk-filled lines # assumed to be comments $fieldname = undef if (($line =~ m/^\s+$/) or ($line =~ m/^\*+$/)); chomp($line); # Assumes colons do not appear except in lines with field names if ($line =~ m/:/) { ($fieldname, $fieldvalue) = split(/:/, $line, 2); # Remove trailing spaces from field name, # leading spaces from field value $fieldname =~ s/\s+$//g; $fieldvalue =~ s/^\s+//g; } else { $fieldvalue = $line; } # Skip remaining steps if line was a comment next unless (defined($fieldname)); if (exists($pkg{$fieldname})) { $pkg{$fieldname} .= $multiline_seperator . $fieldvalue; } else { $pkg{$fieldname} = $fieldvalue if ((length($fieldvalue)) and (defined($fieldname))); } } # For testing only foreach my $k (sort(keys(%pkg))) { print($k, "\t:\t", $pkg{$k}, "\n"); } __DATA__ a-sendee: data1 data1 data1 b-sender: data2 c-date: data3 *************************************** Copyright blah blah blah d-postage: data4 e-deliverydate: data5 *************************************** unimportant text f-name: data6 g-paycode: data7 g-paycode: data8 location 1 h-state: data9 i-zip: data10 location 2 h-state: data11 i-zip: data12
Update: I must admit that I read the question and answered before reading carefully all responses, especially the response by jonjacobmoon, which basically spelled out what I coded.

In reply to Re: Probably very simple (for those in the know) by atcroft
in thread Probably very simple (for those in the know) by Anonymous Monk

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.