I have created two named capture variables in the regex and the second one doesn\'t seem to return any value while the first one can. I am not sure why..here is the code.
You probably mean:
my $string = 'test [google] another test [windows]'; if( $string =~ /.*?\[(?\w+)\].*?\[(?\w+)\]/i ) { say $+{firstBracket}; say $+{secondBracket}; }
output
google windows
or
my $re = qr/.*?\[(?\w+)\].*?\[(?\w+)\]/i; if( $string =~ $re ) { ... }
with same output...