Adding some inferred context, but avoiding the implied slurp, the following seems to address the issue:

use strict; use warnings; use Data::Dump::Streamer; my @record; my @records; while (defined (my $line = <DATA>) or @record) { my $recordStart = (! defined $line) || ($line =~ /(RECORD .*)/); next if ! @record and ! $recordStart; chomp $line if defined $line; if (! $recordStart || ! @record) { push @record, $line; next; } die "Corrupted record: \n" . (join " \n", @record) if @record < 3; my $rec = trim ($1); my ($id, $name) = map {trim ($_)} $record[1] =~ /(\d+)(.*)/; push @records, {rec => $rec, id => $id, name => $name}; $records[-1]{date} = trim ($1) if $record[2] =~ s!^.*?(\d{2}\/\d{2 +}\/\d{4})!!; $records[-1]{address} = trim ($record[2]); @record = defined $line ? ($line) : (); } Dump (\@records); sub trim { my ($str) = @_; return if ! defined $str; $str =~ s/^\s+//; $str =~ s/\s+$//; return $str; } __DATA__ RECORD 1 ###### Full Name 1a Street Address 1a City 1a ST1a Zip_1a + COUNTY 1a 0######## Full Name 1b abcABCabc 99/99/9999 Street Address 1b City 1b ST1b Zip_1b + COUNTY 1b RECORD 2 ############ Full Name 2a 99/99/9999 Street Address 2a City 2a ST2a Zip_2a + COUNTY 2a 0### Full Name 2b abcABCabc 99/99/9999 Street Address 2b City 2b ST2b Zip_2b + COUNTY 2b

Prints:

$ARRAY1 = [ { address => 'Street Address 1a', id => 1, name => 'a', rec => 'RECORD 2' }, { address => 'Street Address 2a', date => '99/99/9999', id => 2, name => 'a', rec => undef } ];

True laziness is hard work

In reply to Re: Parsing Regex by GrandFather
in thread Parsing Regex by deMize

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.