in reply to Using a regex capture as part of a varible

You will probably get a warning, but there is an outside chance that sed qr{("name": "$section",\n.*\n.*)­}, '\\1' . $json, $groups_file, multiline => TRUE might work.

For compatibility, Perl also recognizes '\N' for one-digit N in regex substitutions if there are sufficient capture groups in the pattern.