http://www.perlmonks.org?node_id=1016714


in reply to Re: How to store matched $1 values one by one to array?
in thread How to store matched $1 values one by one to array?

A minor variation using the  \K (5.10+) and  s///r (5.14+) regex operators, and no capture groups. (Note: I use  \x22 instead of  " (double-quote) in the  s///r substitution because the Windoze CLI gets a little freaky over unpaired double-quotes.)

>perl -wMstrict -MData::Dump -le "my $line = q{xxx:agent_id=>foo,yyy:agent_id=>b\"a\"r,zzz:agent_id=>\"baz\",qqq +}; ;; my @agents = map s{\x22}{}xmsgr, $line =~ m{ :agent_id=> \K [^,]+ }xmsg; ;; dd \@agents; " ["foo", "bar", "baz"]