use 5.14.0; sub endOfBlock { my ($iface, $ref_alsHoA) = @_; say "interface: $iface"; for my $k (sort keys %$ref_alsHoA) { say "$k: ", join ', ', @{$ref_alsHoA->{$k}}; } %$ref_alsHoA = (); } my %alsHoA; my $iface; while () { if (/^###### interface (.+) ######$/) { endOfBlock($iface, \%alsHoA) if defined $iface; $iface = $1; } if (/^(Information \d+)(.+)/) { push @{$alsHoA{$1}}, $2; } } endOfBlock($iface, \%alsHoA) if defined $iface; __DATA__ ###### interface INFORMATION1 ###### Information 1a Information 1b Information 1c Information 2a Information 3a Information 3b ###### interface INFORMATION2 ###### Information 1a Information 1b Information 1c Information 2a Information 3a