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


in reply to Quantified named captures in 5.10

I don't think it's the most graceful solution, but I was able to throw this together in a hurry. It does look like the official rule is that you need to explicitly specify each occurrence of digit that you care about. That doesn't really make sense to me either. Which probably means there is another approach we're missing.

use feature qw(:5.10); use strict; use warnings; my $str = 'Digits: 123689'; if ($str =~ m{Digits: \s* (?<digits>\d+)}x) { my @digits = split //, $+{digits}; say "Digits: " , join(', ', @digits); } else { say "No match"; }

Update: This version looks like a slightly better solution for a more general purpose chain, but I still like it better the way you're thinking of.

use feature qw(:5.10); use strict; use warnings; my $str = 'Digits: 123689'; if ($str =~ m{Digits: \s* (\d+)}x) { my $digit_str = $1; my @digits; while ($digit_str =~ m{(?<digit>\d)}gx) { push @digits, $+{digit}; } say "Digits: " , join(', ', @digits); } else { say "No match"; }