title: Why does my Perl CGI script cause a 500 internal server error?
body: <p>I get a 500 internal server error when I try to run the code below in a web server which supports perl:</p>
  
  <pre><code>#! /usr/bin/perl
  
  use LWP;
  
  my $ua = LWP::UserAgent-&gt;new;
  $ua-&gt;agent("TestApp/0.1 ");
  $ua-&gt;env_proxy();
  
  my $req = HTTP::Request-&gt;new(POST =&gt; 'http://www.google.com/loc/json');
  
  $req-&gt;content_type('application/jsonrequest');
  $req-&gt;content('{ "cell_towers": [{"location_area_code": "55000", "mobile_network_code": "95", "cell_id": "20491", "mobile_country_code": "404"}], "version": "1.1.0", "request_address": "true"}');
  
  my $res = $ua-&gt;request($req);
  if ($res-&gt;is_success) {
  print $res-&gt;content,"\n";
  } else {
  print $res-&gt;status_line, "\n";
  return undef;
  }
  </code></pre>
  
  <p>But there is no error when I run the code below:</p>
  
  <pre><code>#! /usr/bin/perl
  
  use CGI::Carp qw(fatalsToBrowser);
  
  
  print "Content-type: text/html\n\n";
  print "&lt;HTML&gt;\n";
  print "&lt;HEAD&gt;&lt;TITLE&gt;Hello World!&lt;/TITLE&gt;&lt;/HEAD&gt;\n";
  print "&lt;BODY&gt;\n";
  print "&lt;H2&gt;Hello World!&lt;/H2&gt; &lt;br /&gt; \n";
  
  foreach $key (sort keys(%ENV)) {
  print "$key = $ENV{$key}&lt;p&gt;" ;
  }
  print "&lt;/BODY&gt;\n";
  print "&lt;/HTML&gt;\n";
  </code></pre>
  
  <p>So I think there is some problem with my code. When I run the first perl script in my local machine with the -wc command, it says that the syntax is OK. Help me please.</p>