while (pos($_) < length($_)) { if (m{ \G (\w+) \s* = \s* (?=\S) }gcx) { # key-value pair is fixed-up in post-processing push @args [ $1 ]; } elsif (m{ \G (\w+) (?= \s | \z ) \s* }gcx) { push @args, $1; } elsif (m{ \G (['"]) ( \\. | [^\\] )*? \1 (?= \s | \z ) \s* }gcxs) { (my $quoted = $2) =~ s/\\(.)/$1/g; push @args, $quoted; } elsif (m{ \G (:) \s+ }) { push @args, $1; } else { die "parsing error\n"; } } for (my $i = 0; $i < @args; ++$i) { next unless ref $args[$i]; my $value = splice @args, $i+1, 1; die "parsing error\n" if !defined($value) || ref $value; $args[$i] = [ $args[$i], $value ]; }