In Perl regular expressions, (?(DEFINE)(? creates a referencable pattern which can be executed by the "recursion" mechanism e.g. (?&NAME). This is useful if the "..." is a parameter with unknown internal capture groups. As perlre alludes to, the (DEFINE) has to be placed at the end of the regex if evaluated in List context (because extra 'undef' values corresponding to inner groups in the "..." will be returned).
I'm wondering why this construct exists in Perl because AFAICT ordinary capture groups can be used by just inserting an (*ACCEPT) to prevent directly executing them.
For example, given $_ = "beforeMIDDLEafter" the following seem to do exactly the same:
/ ^ (\w*?) (?&SUB) (\w*) (*ACCEPT) (?MI(D)(?1)LE) /x;
/ ^ (\w*?) (?&SUB) (\w*) (?(DEFINE)(?MI(D)(?1)LE)) /x;
Both set @{^CAPTURE)=("before", "after") and both return ("before","after",undef,undef) in list context.
My question is: Are these exactly equivalent? Does the (DEFINE) construct provide any additional or different capability?