use Data::Dumper; %hash = (split /\:/, (split /;/ $string)); print Dumper \%hash; #### $VAR1 = { '3' => undef };