Regex string substitution and capture groups

View thread

nimaimalle

I'm trying to do something like this, but I'm getting a literal "$1" substituted instead of the value of the capture group.

if $data =~ s/(\[[^\]]+\])/"$1"/g log_info($1);

$data ends up containing a "$1" while the log_info statement correctly logs the value of captured group $1.

Is there a way to use s/// and capture groups in the substitution? I also tried \1 and \\1.