if ( my (@caps) = ($line =~ $re) ) { no warnings 'uninitialized'; @caps = () if $caps[0] ne $1; # reset pseudo captures $cb->(@caps); last; } #### my (@matches) = ($line =~ $re) if (defined $&) { $cb->(@matches); last; } #### use v5.12; use warnings; for my $str ("AB","") { say "****** str=<$str>"; for my $re ( qr/../, qr/(.)(.)/, q/XY/, q/(X)Y/, q// ) { say "--- re=<$re>"; my @captures = $str =~ $re; if ( defined $& ) { say "matched" } else { say "no match" } if (defined $1) { say "with captures <@captures>"; } else { say "no captures"; } } } #### ****** str= --- re=<(?^u:..)> matched no captures --- re=<(?^u:(.)(.))> matched with captures --- re= no match no captures --- re=<(X)Y> no match no captures --- re=<> matched no captures ****** str=<> --- re=<(?^u:..)> no match no captures --- re=<(?^u:(.)(.))> no match no captures --- re= no match no captures --- re=<(X)Y> no match no captures --- re=<> matched no captures