in reply to How can i catch strings matching a regex across multiple lines?

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

Replies are listed 'Best First'.
Re^2: How can i catch strings matching a regex across multiple lines?
by ww (Archbishop) on Jul 01, 2012 at 13:20 UTC
    /me .oO ' ... at last -- a tested solution!'

            + +

Re^2: How can i catch strings matching a regex across multiple lines?
by babelfish (Initiate) on Jul 01, 2012 at 20:11 UTC

    Thanks, that one works well for me!

    So, i need to give myself an hour's detention on proper data munging :)