use warnings; use strict; my $str = "word1: 12345, word2: true"; my %hash = split /[:,]\s*/, $str; print "$_: $hash{$_}\n" for sort keys %hash; #### word1: 12345 word2: true