my $data = "aap=10 20 30 noot=50 60 mies=20 teun=3"; my %foo; while ($data =~ m/(\S+)=(\S+($|([^=]+\s+)+))/g) { $foo{$1}=$2; }