my %hash; for my $nar ( @nar ) { my ( $key1, $key2 ) = split /\s*-\s*/, shift @$nar; push @{ $hash{ $key1 }{ $key2 } }, $nar; }