my %record; while () { if (/----switchname----/) { chomp($record{switchname} = ); } elsif (/^port-channel (\d+)/) { $record{channel} = $1; } }