my @lines = split(/^/, $config); # Iterate over the lines. foreach my $line (@lines) { if ($line =~ /description\s+ ([^\"][^\s]+)/x) { my ($key) = "$_"; next if ($line =~ /^\s*$/) } if ($line =~ /switchport trunk allowed vlan\s*(.*)/) { my ($value) = "$_"; } $hash1{$key} = $value ; }