my ($type, $restofstring) = /^type=(\w+) (.+)$/; for $restofstring (split) { my ($key, $val) = split /=/, $restofstring; $hash{$type}{$key} = $val; } #### my ($type, $restofstring) = /^type=(\w+) (.+)$/; for $token ( split ' ', $restofstring ) { my ($key, $val) = split /=/, $token; $hash{$type}{$key} = $val; }