while () { chomp; print "\n$1 =" and next if /^(interface\s.+)/; print "$1" and next if /^\s+(switchport description\s.+)/; } #### my (%data, $last); while () { #~ print STDERR $_; chomp; if (/^(interface\s.+)/) { $last = $1; $data{$last} = ''; next; } $data{$last}=$1 and next if /^\s+(switchport description\s.+)/; } ##now print for ( sort keys %data ) { print "$_ = $data{$_}\n" }