title: Getting process id of background process in Perl
body: <p>The following bash script works well</p>
  
  <pre><code>#! /bin/bash
  sleep 2 &amp; echo $!
  </code></pre>
  
  <p>If I try to do this in Perl:</p>
  
  <pre><code>use warnings;
  use strict;
  my $pid=qx{bash -c 'sleep 2 &amp; echo $! '};
  print "$pid\n";
  </code></pre>
  
  <p>it does not return immediately, and it also gives empty output for <code>$pid</code>.</p>