#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $data = {}; my $channel = undef; while (defined (my $record = )) { chomp $record; if ( $record =~ /^$/ ) { $channel = undef; # port-channels are seperated by blank lines next; } # I know I'm not in a record when I look for a port-channel # I could add a die here to signal problems with the format if ( !defined channel && $record =~ /^port-channel (\d+)$/ ) { $channel = $1; # this signals a new channel next; } # I check if I'm in a record and if so I test for fc's if ( $defined $channel && $record =~ /fc(\d+)\/(\d+)\s+\[(.+)\]/ ) { my $port = "fc$1\/$2"; my $status = $3; die "something wrong" if defined $data->{$channel}->{$port}; $data->{$channel}->{$port} = $status; next; } } print Dumper $data; __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] *