#!/usr/bin/perl # http://perlmonks.org/?node_id=1198743 use strict; use warnings; use Data::Dump 'pp'; my @array = ('a', 1, 2, 3, 4, 'b', 6, 7, 8); my $ref; my %hash = map { /\D/ ? ($_ => $ref = []) : (push @$ref, $_) x 0 } @array; pp \%hash; #### { a => [1 .. 4], b => [6, 7, 8] }