in reply to smart match capture

Yes, you can do that. You just have to use the appropriate special variables:

use strict; use warnings; use v5.12; my @array = ( "First try this.", "Second try that.", "Third tried another.", "Fourth tried this last.", ); if( @array ~~ m/tried/p ) { say ${^PREMATCH} . ${^MATCH} . ${^POSTMATCH}; }

The output is:

Third tried another.

So it appears that the smart match operator is smart enough to stop executing the test (in boolean context) as soon as the first successful match flips the conditional to true.

Note the use of the /p modifier, to enable these lower-impact versions of $`, $&, and $'


Dave