my $data = join('',); my @chunk = split(/^\d/m, $data); foreach (@chunk) { process_array( split(/\n/s, $_) ) }