I tried to store the first group in @a1 and second group in @a2
my $string = "abc123def456abc321def654";
my (@a1,@a2) = $string =~m/abc(\d+)def(\d+)/g;
$, = "\n";
print @a1;
Result is 123 456 321 654 and then @a2 is empty. But i want the result is @a1 = 123 321; @a2 = 456 654
For this result i tried hash , for to store the keys are first grouping and the values are second grouping but the problem is duplicates are removed. Any possible way for to do it with a single regex matching ?
I tried eval group within pattern matching. I get the correct result from @a1 but @a2 going wrong. And don't know what is the problem?
my (@a1, @a2);
$string =~m/abc(\d+) (?{push @a1, $1}) def(\d+)(?{push @a2,$2 }) \G/x;
@a1 result is
1234
321
666
@a2 result is
4567
456
45
4
654
65
6
777
77
7