 <pre><code>my $newvar = $text =~ m/ quick (.*) dog /; </code></pre> <p>is an assignment in scalar context, and assigns either <code>1</code> or <code>undef</code>.</p> <p>You want to make this assignment in list context</p> <pre><code>my ($newvar) = $text =~ m/ quick (.*) dog /; </code></pre> <p>which assigns the captured groups from the regular expression.</p> <p>The difference between scalar and list contexts is one of the trickiest things to get used to in Perl.</p> <p>Note that captured groups from regular expressions in Perl also get assigned to the special variables <code>$1</code>, <code>$2</code>, ... . So you also could just have said</p> <pre><code>print "$1\n"; </code></pre>