Now that's something I never thought to try—the behavior of @+ and @- is totally different! (Hey Japhy, want to check out why?)

I can put that into a function call, along with the other code in a comment, for maintainability. If a documented way arrives, easy to change. If it stops working, delete two lines and the other way takes over.

This appears to be a bug. perlvar says that $#+ should return the number of successful groupings, but it doesn't -- it returns the number of attempted groupings. $#-, on the other hand, works as expected.

This array holds the offsets of the ends of the last successful submatches in the currently active dynamic scope. $+[0] is the offset into the string of the end of the entire match. This is the same value as what the pos function returns when called on the variable that was matched against. The nth element of this array holds the offset of the nth submatch, so $+[1] is the offset past where $1 ends, $+[2] the offset past where $2 ends, and so on. You can use $#+ to determine how many subgroups were in the last successful match. See the examples given for the @- variable.

It doesn't say that it tells you how many capturing parens were successful—rather, how many sets of capturing parens were present in the last successful match. That's consistant with its observed behavior.

The docs for @- says that the array element will be undef if the capture paren did not match, which is not claiming that trailing undef entries are deleted from the array.

I'd rather have a clear way to ask for either value than to use sideband information like this.