Further limitations with s/// reported in bug report 21843 # PROBLEM $1 and $2 in replacement are NOT correlated to pattern #!/usr/bin/perl -w my ($from, $to, $text, $line); $text = "head middle 1 middle 2 middle 3 tail"; print "\noriginal text\n$text\n"; $from = "(head).*(tail)"; $to = '${1}NEW_MIDDLE${2}'; $text =~ s/$from/$to/s; print "\nfinal text\n$text\n"; ######################################################################## ######## ###### Here try to substitute entire expression ###### used various quoting and backslashing of $str when defined ###### tried eval, and {}, () on $text =~ line #!/usr/bin/perl -w my ($from, $to, $text, $line); $text = "head middle 1 middle 2 middle 3 tail"; print "\noriginal text\n$text\n"; $str = quotemeta's|(head).*(tail)|${1}NEW_MIDDLE{2}|s'; #$str = 's|(head).*(tail)|\${1}NEW_MIDDLE\${2}|s'; $text =~ $str; # <=== try to substitute entire expression # replacement is always literal print "\nfinal text\n$text\n";Thread Previous | Thread Next