in reply to backreference replaced as literal or just fails

Please read Writeup Formatting Tips and How (Not) To Ask A Question. In particular, wrap your input file in code tags, since it is getting misformatted. Also, you are binding $rrow_test to your substitution, but don't give us a value. You probably want to reformat your open statement to open FILE, "<", $file or die "Can't open $file: $!\n"; as well, but that's more subjective.

Replies are listed 'Best First'.
Re^2: backreference replaced as literal or just fails
by brwarn (Novice) on Mar 10, 2009 at 19:32 UTC
    Sorry for missing the input part. With respect to your binding point, I must not understand the usage. I understand
    $rrow_test =~ s/$rex[0]/$rex[1]/ig;
    to mean
    "Replace the first occurrence of $rex[0] with $rex[1]."
    I'm setting the $rex array values on the 'split' line of the code. Am I understanding your point/question correctly or have I missed the mark altogether? Thanks.
      The "binding" issue is that you didn't give us any possible values for $rrow_test, thus making it harder to determine intent. In any case, the issue you are likely encountering is that you expect your strings to get interpolated twice. According to Regexp Quote-Like Operators, variables you pass get interpolated at run time. This means that "$rex[1]" gets interpolated to "$1", the literal value (Update: as GrandFather points out below). Your solution is to doubly interpolate the string, using the ee modifier. Note this is potentially a serious security risk.

      Also note your i modifier is useless in your current construct, as you already handle both upper- and lower-case letter.

      "Replace the first occurrence of $rex[0] with $rex1."

      Actually /g means replace all occurrences.