$regex = qr# (\d) (??{ my $c = $1 unless defined $c; ++$c })+ #x;