my %all_the_stuff = (); my $current; while( <> ){ chomp; next unless length; if( m/^KEY: (.+)/ ){ $current = { OID => [], #you migth want to put these two NAME => [], # together, i don't know ERROR => undef, }; $all_the_stuff{ $1 } = $current } next unless $current; if( m/^(OID|NAME): (.+)/ ){ push @{$current->{$1}},$2 } elsif( m/^Error Status (.+)/ ){ $current->{ERROR} = $1; $current = undef; #error status is final statement } }