$port_channels[0]{ name => "port-channel 1" , members => [ 'fc2/5' , 'fc1/5' ] }; $port_channels[1]{ name => "port-channel 3" , members => [ 'fc1/1' ] }; #### $port_channels{1}{ members => [ 'fc2/5' , 'fc1/5' ] }; $port_channels{3}{ members => [ 'fc1/1' ] }; #### $port_channels{1}[ 'fc2/5' , 'fc1/5' ]; $port_channels{3}[ 'fc1/1' ]; #### use strict; use warnings; my %port_channels; { my $channel; my $in_ports = 0; while () { if (/^port-channel\s+(\d+)/) { $channel = $1; $port_channels{$channel} = []; $in_ports = 0; next; } next unless defined $channel; if (/^\s*Ports:\s+(\S+)\s+\[/) { $in_ports = 1; push(@{$port_channels{$channel}}, $1); next; } if ($in_ports) { if (/\s+(\S+)\s+\[/) { push(@{$port_channels{$channel}}, $1); next; } $in_ports = 0; } } } require Data::Dumper; print(Data::Dumper::Dumper(\%port_channels)); __DATA__ port-channel 1 Administrative channel mode is on Operational channel mode is on Last membership update succeeded First operational port is fc1/5 2 ports in total, 2 ports up Ports: fc2/5 [up] fc1/5 [up] * port-channel 3 Administrative channel mode is on Operational channel mode is on Last membership update succeeded First operational port is fc1/1 1 port in total, 1 port up Ports: fc1/1 [up] * #### $VAR1 = { '1' => [ 'fc2/5', 'fc1/5' ], '3' => [ 'fc1/1' ] };