my $tag = "Invalid"; my %results; while (<>) { if (/^ER/) { last; } elsif (/^([A-Z]{2})\s+(.*)/) { # might need adjustment $tag = $1; push @{$results{$tag}}, $2; } elsif (/^\s+(.*)/) { # might need adjustment push @{$results{$tag}}, $1; } else { die "I don't understand $_"; } }