$test="\$\{This\$\{One\}and\$\{also\}this\}"; $test=~/\$\{(([^\{\$\}]*(?:\$\{[^\$\{\}]+\}[^\$\{\}]*)*))\}/gxs; print "test:$1";