#! /usr/local/bin/perl5.9.5 use v5.9.5; use Data::Dumper; my $re; $re = qr/The animal is: (?monkey|tiger|lion)/; my $string = 'The animal is: tiger'; if ($string =~ $re) { say "Successfully matched."; print Dumper(\%+); } #### #! /usr/local/bin/perl5.9.5 use v5.9.5; use Data::Dumper; my $re; $re = qr/ (?(DEFINE) (?The \s animal \s is: \s (?monkey|tiger|lion)) ) (?&phrase) /x; my $string = 'The animal is: tiger'; if ($string =~ $re) { say "Successfully matched."; print Dumper(\%+); print Dumper(\%-); } #### Note that capture buffers matched inside of recursion are not accessible after the recursion returns, so the extra layer of capturing buffers is necessary. Thus $+{NAME_PAT} would not be defined even though $+{NAME} would be [see example].