title: Circumstances under which die() does not exit a Perl script?
body: <p>I'm debugging a really weird problem with a long-running Perl script.</p>
  
  <p>The problem is that the script does not exit on <code>die()</code> as expected. Instead the script just hangs without returning.</p>
  
  <p>I've not defined any error handlers myself so I would assume that <code>die()</code> would lead to an immediate termination of the script.</p>
  
  <p>This is the basic structure of the script and the modules used:</p>
  
  <pre><code>#!/usr/bin/perl
  
  use strict;
  use utf8;
  use warnings;
  
  use DBI; # with MySQL driver ("dbi:mysql:database=...")
  use Geo::IP;
  use POSIX;
  use URI::Escape;
  
  open(COMMAND, 'command_line |');
  while (&lt;COMMAND&gt;) {
      #
      # .. stuff that can go wrong ..
      #
      die("I'm expecting the script to terminate here. It doesn't.") if ($gone_wrong);
  }
  close(COMMAND);
  </code></pre>
  
  <p>What could be the explanation to this behaviour? Is any of the modules used known to set up error handlers that could explain the script hanging on <code>die()</code>?</p>