use v5.12; use warnings; say "-"x10, ' ?'; for my $i (1..3) { say "Match $i" if '2' =~ m/(?{say "in $i"})$i/; } say "-"x10, ' ??'; for my $i (1..3) { say "Match $i" if '2' =~ m/(??{say "in $i";$i})/; } #### # This is perl 5, version 40, subversion 3 (v5.40.3) built for aarch64-android Compilation started at Sat Apr 18 20:38:08 perl tst_re.pl ---------- ? in 2 Match 2 ---------- ?? in 1 in 1 in 2 Match 2 in 3 in 3 Compilation finished at Sat Apr 18 20:38:08, duration 0.03 s