$ perl -MData::Dumper -E ' > $text = q{a 2 b 4,5,6 c d e 45,657,-67}; > %hash = > map { $_->[ 0 ] => [ split m{,}, $_->[ 1 ] ] } > sub { > push @arr, [ $1, $2 ] > while $_[ 0 ] =~ m{\s*([a-z])\s+([-,\d]*)}g; > return @arr; > }->( $text ); > say Data::Dumper->Dumpxs( [ \ %hash ], [ qw{ *hash } ] );' %hash = ( 'e' => [ '45', '657', '-67' ], 'c' => [], 'a' => [ '2' ], 'b' => [ '4', '5', '6' ], 'd' => [] ); $