title: How can I read the error output of external commands in Perl?
body: <p>As part of a larger Perl program, I am checking the outputs of <code>diff</code> commands of input files in a folder against reference files, where a blank output (a match) is a passing result, and any output from diff is a fail result.</p>
  
  <p>The issue is, if the target folder is short on the number of expected files, the exception diff throws doesn't come as output, creating false passes.</p>
  
  <p>Output Example:</p>
  
  <pre><code>diff: /testfolder/Test-02/test-output.2: No such file or directory
  </code></pre>
  
  <p>Test-01: PASS</p>
  
  <p>Test-02: PASS</p>
  
  <p>The code goes as such:</p>
  
  <pre><code>$command = "(diff call on 2 files)";
  my @output = `$command`;
  print "Test-02: ";
  $toPrint = "PASS";
  foreach my $x (@output) {
      if ($x =~ /./) {
          $toPrint = "FAIL";
      }
  }
  </code></pre>
  
  <p>This is a quick hackery job to fail if there is any output from the <code>diff</code> call. Is there a way to check for exceptions thrown by the command called in the <code>backticks</code>?</p>