Capture group contents are dynamically scoped and available to you
outside the pattern until the end of the enclosing block or until the next successful match, whichever comes first. (See "Compound Statements"
in perlsyn.) You can refer to them by absolute number (using "$1" ...

(The reference in the quote above to the discussion in Compound Statements) does not seem to shed any light on the particular question of this post.

In the code example below, some dynamic scoping is clearly taking place since $1 begins and ends undefined. However, $1, set to '1' by the last successful match at the lowest-but-one level of recursion, is propagated upward unchanged through several levels of subroutine 'blocks' (as I understand them) until it exits the topmost. (local-izing $1 within the subroutine has no effect on this behavior.)

Might this behavior have something to do with the recursive nature of the subroutine: the compiler rewrites the recursive call as a branch to a point within the same block, and so $1 is only restored once because there is only one real block exit?

Can anyone throw any light on this? In particular, any links to documentation?

Just in case the behavior above was an artifact of $1 being undefined initially, I tried setting $1 to a defined value via a successful match prior to the print $1/print R()/print $1 sequence. The result is no different: the value $1 starts out with at the 'top' level is the one it winds up with.

I should mention I am running all my example code in this and other postings in this thread under Strawberry 5.14.2.1.

However, $1, set to '1' by the last successful match at the lowest-but-one level of recursion, is propagated upward unchanged through several levels of subroutine 'blocks'

I see no evidence for that. After $1 is set to '1', exactly one more recursive call happens, and there it is printed out. Then the recursion ends, and you don't print $1 anymore.

I don't print $1, but it must be '1' at all higher recursion levels because only that value will result in a sum total of 4.

However, I have not had (and will not immediately have) a chance to ponder your link and other responses.

I suppose my chief confusion stems from the fact that $1 starts out undefined, takes on a bunch of other values, then winds up as it started. If it had finished up as '1', my mind would rest a bit easier, but at some point, and only one point mind you, it's leaving some kind of scope and being restored to the value it had upon entry. I could understand all scopes, I could understand none, but I can't (yet) understand just one!

For clear definition, as $_ value got changed in every recursive call of R() function, $1 value also got changed and in return of every recursive call, the last changed value available and that is the reason for getting '1' 5 times in $1.
For better understanding, here below I have shown how that recursive calls and values of $_ and $1 will be.

Let me repeat what I wrote earlier, but hopefully a bit clearer this time: There is only one variable $1. The first call to m/()/ or s/()// creates the dynamic variable $1, and all subsequent calls modify the existing variable $1. Since there is no mechanism for resetting $1 to a previous value, you can see the last value of $1 in all stack frames that have access to it.

[Your Mother]:I adored the comic and the movie was almost a frame for frame remake (excepting the plot liberties to shorten it) but I still didn't quite like it. What's his nose, Jamie Earl whoever was flawless though.