in reply to Regex to match "this=that" multiple times

Here's another one...

use Data::Dumper; my $text = 'text one="1" two="2" three="3" ... x="y"'; my $attribute_r = qr{ \w+ }xms; my $equals_r = qr{ \s* = \s* }xms; my $value_r = qr{ \" [^"]+ \" }xms; my %value_of; while ( $text =~ s{ ( $attribute_r ) $equals_r ( $value_r ) }{}xms ) { my ( $name, $value ) = ( $1, $2 ); $value =~ tr/"//d; $value_of{ $name } = $value; } print Dumper \%value_of; __END__ $VAR1 = { 'three' => '3', 'one' => '1', 'x' => 'y', 'two' => '2' };

Note the limits, of course: