in reply to How to know that a regexp matched, and get its capture groups?

It then occurred to me that the code won't run if the regexp has no capture groups!

It will run. The match returns 1 in such circumstances.

$ perl -Mv5.14 -e'if ( my @m = "b" =~ /(a)/ ) { say "@m"; }' $ perl -Mv5.14 -e'if ( my @m = "a" =~ /(a)/ ) { say "@m"; }' a $ perl -Mv5.14 -e'if ( my @m = "b" =~ /a/ ) { say "@m"; }' $ perl -Mv5.14 -e'if ( my @m = "a" =~ /a/ ) { say "@m"; }' 1