my ($body) = $slurp =~ /sub\s+$name\s+{\s+(.*?(?=^}\s*$))/sm; #### my ($body) = $content =~ /sub\s+$name\s+{\s+(.*?(?=^}\s*$))/sm; #### $np = qr{ \( (?: (?> [^()]+ ) # Non-parens without backtracking | (??{ $np }) # Group with matching parens )* \) }x;