You can achieve what you want like so:

use warnings; use strict; use Data::Dumper; my $device_id = {}; my $id = ""; while (<DATA>) { chomp; if (m/Logical.+=(.+?)$/) { $id = $1; } else { if (m/.+?\s+?(c.+?)\s+?.+?$/) { push @{ $device_id->{$id} }, $1; } } } print Dumper($device_id); __DATA__ ### HEADING OF RECORD 1 #### Logical device ID=08E1 LINE_THAT_DOES_NOT_BOTHER_ME ANOTHER_LINE_THAT_DOES_NOT_BOTHER_ME 29 8/0/2/1/0.18.152.0.0.6.1 c29t6d1 FA 5eA 30 8/0/3/1/0.17.152.0.0.6.1 c30t6d1 FA 12e 31 8/0/8/1/0.17.150.0.0.6.1 c31t6d1 FA 10eA 32 8/0/9/1/0.18.150.0.0.6.1 c32t6d1 FA 11eA ### HEADING OF RECORD 2 #### Logical device ID=08E2 LINE_THAT_DOES_NOT_BOTHER_ME ANOTHER_LINE_THAT_DOES_NOT_BOTHER_ME 29 8/0/2/1/0.18.152.0.0.4.1 c29t4d1 FA 5eA 30 8/0/3/1/0.17.152.0.0.4.1 c30t4d1 FA 12eA 31 8/0/8/1/0.17.150.0.0.4.1 c31t4d1 FA 10eA 32 8/0/9/1/0.18.150.0.0.4.1 c32t4d1 FA 11eA ### HEADING OF RECORD 3 #### (...)

output: $VAR1 = { '08E2' => [ 'c29t4d1', 'c30t4d1', 'c31t4d1', 'c32t4d1' ], '08E1' => [ 'c29t6d1', 'c30t6d1', 'c31t6d1', 'c32t6d1' ] };

Please, note test your match regexes.
Also Check perldoc perldsc
Hope this helps


In reply to Re: How can i catch strings matching a regex across multiple lines? by 2teez
in thread How can i catch strings matching a regex across multiple lines? by babelfish

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.