use strict; use warnings; my (%hasharr, @hashkeys, $start); while ( my $line = <> ) chomp $line; next unless $line; #skip empty lines. my ($head, $prod) = split /\s*:=\s*/, $line; foreach ($head, $prod) { s/^\s+//; s/\s+$//; } unless ( $start ) { $start = $head; }; push ( @{$hasharr{$head}}, $prod); push @hashkeys, $head; }