my $iname; while() { $iname=$1, next if /port-channel (\d+)/; next if !defined $iname; $hash->{$iname}->{$1} = $2 if (/switchport description To (\w+) ([\d\.]+)/); $Rec2->{$iname}->{$1} = $2 if (m|(fc\d+/\d+)\s+\[(\w+)\]|); }