title: Why does my non-greedy Perl regex match nothing?
body: <p>I thought I understood Perl RE to a reasonable extent, but this is puzzling me: </p>
  
  <pre><code>#!/usr/bin/perl
  use strict;
  use warnings;
  
  my $test = "'some random string'";
  
  if($test =~ /\'?(.*?)\'?/) {
         print "Captured $1\n";
         print "Matched $&amp;";
  }
  else {
         print "What?!!";
  }
  </code></pre>
  
  <p>prints </p>
  
  <blockquote>
    <p>Captured<br>
    Matched '</p>
  </blockquote>
  
  <p>It seems it has matched the ending ' alone, and so captured nothing.<br>
  I would have expected it to match the entire thing, or if it's totally non-greedy, nothing at all (as everything there is an optional match).<br>
  This in between behaviour baffles me, can anyone explain what is happening?</p>