title: How do I fix a multi-line runaway string error in Perl?
body: <p>There are some errors in my Perl script, I looked though the source code but couldn't find the problem. </p>
  
  <pre><code>#Tool: decoding shell codes/making shell codes
  
  use strict;
  use Getopt::Std;
  
  my %opts=();
  getopts("f:xa", \%opts);
  
  my($infile, $hex);
  my($gen_hex, $gen_ascii);
  
  sub usage() {
  print "$0 -f &lt;file&gt; [-x | -a] \n\t";
  print '-p &lt;path to input file&gt;'."\n\t";
  print '-x convert "\nxXX" hex to readable ascii'."\n\t";
  print '-a convert ascii to "\xXX" hex'."\n\t";
  print "\n";
  exit;
  }
  
  $infile = $opts{f};
  
  $gen_hex = $opts{a};
  $gen_ascii = $opts{x};use
  
  
  if((!opts{f} || (!$gen_hex &amp;&amp; !$gen_ascii)) {
  usage();
  exit;
  }
  
  if($infile) {
  open(INFILE,$infile) || die "Error Opening '$infile': $!\n"; 
  while(&lt;INFILE&gt;) {
  #Strips newlines
  s/\n/g;
  #Strips tabs
  s/\t//g;
  #Strips quotes
  s/"//g;
  $hex .= $_;
  }
  }
  
  if($gen_ascii) {
  
  # \xXX hex style to ASCII
  $hex =~ s/\\x([a-fA-F0-9]{2,2})/chr(hex($1)/eg;
  }
  elsif ($gen_hex) {
  $hex =~ s/([\W|\w)/"\\x" . uc(sprintf("%2.2x",ord($1)))/eg;
  } 
  
  print "\n$hex\n";
  if($infile) {
  close(INFILE);
  }
  </code></pre>
  
  <p>gives me the errors </p>
  
  <pre><code>Backslash found where operator expected at 2.txt line 36, near "s/\"
  (Might be runaway multi-line // string starting on line 34) 
  syntax error at 2.txt line 25, near ") {"
  syntax error at 2.txt line 28, near "}"
  syntax error at 2.txt line 36, near "s/\"
  syntax error at 2.txt line 41. nar "}"
  Execution of 2.txt aborted due to compilation errors
  </code></pre>
  
  <p>Do you see the problems?</p>