use re 'debug'; my $braces = qr/(?\{ ([^\{\}]* | (?&braces))*? \} )/x; # ^ Compiling REx "(?\{ ([^\{\}]* | (?&braces))*? \} )" Final program: 1: OPEN1 'braces' (3) 3: EXACT <{> (5) 5: MINMOD (6) 6: CURLYX[0] {0,32767} (30) 8: OPEN2 (10) 10: BRANCH (23) 11: STAR (27) 12: ANYOF[\0-z|~-\377][{unicode_all}] (0) 23: BRANCH (FAIL) 24: GOSUB1[-23] (27) 27: CLOSE2 (29) 29: WHILEM[2/1] (0) 30: NOTHING (31) 31: EXACT <}> (33) 33: CLOSE1 'braces' (35) 35: END (0) anchored "{" at 0 floating "}" at 1..2147483647 (checking floating) minlen 2 Freeing REx: "(?\{ ([^\{\}]* | (?&braces))*? \} )"