title: How to find a variable and replace it with other variable in Perl?
body: <p>I have tried the below Perl command to find a <code>$from_word</code> variable and replace it with <code>$to_word</code> variable in the <code>$bat_file_path</code> file.</p>
  
  <pre><code>system("perl -i -p -e 's/$from_word/$to_word/ee' $bat_file_path");
  </code></pre>
  
  <p>but I get error as</p>
  
  <pre><code>Substitution replacement not terminated at -e line 4.
  </code></pre>
  
  <p>Also it did not replaced as expected.</p>
  
  <p>Please help me out of this concern.</p>
  
  <pre><code>sub change_cg_name {
    if(!-e $output_running) {
      print ("show running file not available. test case failed. [$output_running]");
      return 0;
    }
    if(!-e $bat_file_path) {
      print ("bat file not available test case filed. [$bat_file_path]");
      return 0
    }
    my $from_word=`grep 'config-group type node IMPT_' $bat_file_path  | awk '{print \$(4)}'`;
    my $to_word=  `grep 'config-group type node IMPT_' $output_running | awk '{print \$(4)}'`;
    print("from WORD IS [$from_word]");
    print("TO WORD IS [$to_word]");
    if($to_word ne "") {
      if (index($to_word, "IMPT_") != -1) {
        system("perl -i -p -e 's/"$from_word"/"$to_word"/ee' $bat_file_path");
        system("perl -p -i -e 's/\r\n$/\n/g' $bat_file_path");
        print("ARUL changed the impt name in the bat file [$to_word] and file [$bat_file_path]");
        return 0;
      }
    }
  }
  </code></pre>