This is clever and I like it. It lets (?{...}) use a lexical safely. I learned it from almut at http://perlmonks.org/?node_id=592234>
sub ... {
my @lex;
... =~ /...(?{ sub { ... @lex }->( ... ) }).../;
}
If (?{...}) used @lex directly then the single closure embedded in the regexp would have bound once and forever to only one instance of @lex. All calls to this after the first would be using the @lex from back in time and not the current one.
When (?{sub{ }->( )} uses @lex inside the newly created closure it works because the inner closure has to look at runtime to find @lex. Static (?{}) doesn't have it. The function containing both does and it has the current @lex. sub {}->() binds to the proper, current @lex and everyone is happy.
It's only one level of indirection away so I'm surprised to be learning of this just today. I mean, I can explain why this works, it just never occurred to me that it was possible.