in reply to Length of first captured match

Another way - force array context on the regex, make an anon array ref, dereference, and shift - this gets you the first element (or zero'th index).
Once you have that, "length" is easy. Code does not look as bad as it sounds ..
my $len = length shift @{ [ $x =~ /(\d+)$/ ,'' ] };
The additional ",''" is necessary to satisfy "use warnings" - which would otherwise complain about "Use of uninitialized value in length at line xx" in the case that the match was not found.
In this case, the empty string arrives, available to be "shift"ed, allowing "length" to evaluate the length of the empty string, instead of an undef value.

     "For every complex problem, there is a simple answer ... and it is wrong." --H.L. Mencken

Replies are listed 'Best First'.
Re^2: Length of first captured match
by ikegami (Patriarch) on May 07, 2006 at 01:27 UTC

    ${[...]}[0]
    is much less efficient and harder to read than the list slice
    (...)[0]
    the OP proposed. The advatage is that yours can be embedded into an interpolating string.