while (pos($tag) < length($tag)) { if (m{ \G (\w+) \s* = }gcx) { push @args [ $1 ]; } elsif (m{ \G (\w+) (?= \s* | \z ) \s* }gcx) { push @args, $1; } elsif (m{ \G (['"]) ( \\. | [^\\] )*? \1 \s* }gcx) { (my $quoted = $2) =~ s/\\(.)/$1/g; push @args, $quoted; } else { die "parsing error\n"; } } for (my $i = 0; $i < @args; ++$i) { $args[$i][1] = splice(@args, $i + 1, 1) if ref $args[$_]; }