title: Perl CGI script reads text file content with backslash incorrectly
body: <p>I have a simple text file with lines containing backslash (\something). When reading it in Perl scripts on the command line, I get the text lines exactly as they are in the file. When EXACT SAME lines of code are copied and pasted into a CGI script, the text file contents are read differently by adding one more backslash for each backslash. I spent two days on searching various forums (StackOverflow, PerlMonks, etc.) but could not find probable cause. Below is the code and text file. Any help is greatly appreciated.</p>
  
  <pre><code>**~/tests/backslash&gt; cat /home/user1/tests/backslash/pattern.txt**
  more LaTex formatted strings.
  \frac{a}{b} = \frac{5}{7}
  **~/tests/backslash&gt;  cat test.pl**
  my $file = "/home/user1/tests/backslash/pattern.txt";
  print STDERR "Attempting to open $file and read the last line...\n";
  open(FH, "&lt; $file") or die "ERROR: can't open $file: $!";
  my @lines = &lt;FH&gt;;
  close(FH);
  my $myExpression = $lines[scalar(@lines) - 1];
  chomp($myExpression);
  print STDERR 'Expr: [' . $myExpression . "]\n";
  my $retString = qq{{ "result" : "$myExpression" }};
  print STDERR $retString . "\n";
  **~/tests/backslash&gt; ./test.pl**
  Attempting to open /home/user1/tests/backslash/pattern.txt and read the last line...
  Expr: [\frac{a}{b} = \frac{5}{7}]
  { "result" : "\frac{a}{b} = \frac{5}{7}" }
  **~/tests/backslash&gt;**
  </code></pre>
  
  <p>This exact same code in CGI script produces the following output:</p>
  
  <p>
  <a href="https://i.stack.imgur.com/Zdkab.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Zdkab.png" alt="Output from CGI script"></a>
  
  I split the string into array and examined each character (in the CGI script), which has two backslashes before 'frac'. Dumper confirms this as well. I tried to substitute two backslashes with '\' but was not successful with that either. I hit so many other problems in understanding and fixing this problem (eg. CGI script could not open the same text file from /tmp[file not found], substituting two backslashes with \ in various ways failed with syntax errors, variable values are getting unexpected characters when substituting, etc. but I am focusing on the core problem of backslashes in this question.) I made all the 'use' classes exactly the same in the command line script and CGI script just in case, even though command line script does not use CGI, JSON, etc.</p>
  
  <p>I am perplexed why exact same Perl code behaves differently in cgi-bin. Any help, suggestion, pointers, or discussion on this is appreciated.</p>
  
  <pre><code>My environment:
  Suse Linux 13.1
  Perl 5.18.1
  Apache 2.4.6
  Bash 4.2.53
  </code></pre>