use strict; use warnings; my $str = "name:val with a :"; my %hash; $hash{$_->[0]} = $_->[1] for [split /:/, $str, 2]; print map {"$_:$hash{$_}\n"} keys %hash; #### name:val with a :