foreach (split " ", $data) { if (/^([^=]*)=(.*)/) { $hash{$last=$1}=$2 } elsif (defined $lastkey) { $hash{$last} .= " $_" } }