title: Negative lookbehind assertion in Perl
body: <p>I have a set of file-paths, and I want to list all file-paths that do not contain <code>x/y/z/</code>. The other constraint is that I cannot use <code>print if !m{x/y/z/}</code> since I don't have write permissions on the script. I can provide the script with regexp patterns to <em>include</em> (as command-line-options), i.e., everything that matches will be printed.</p>
  
  <p>This is my attempt. I am trying to match all lines that <em>do not</em> have <code>x/y/z/</code> before them.</p>
  
  <pre><code>#!/usr/bin/perl
  use warnings;
  use strict;
  
  while(&lt;DATA&gt;) {
     print if m{(?&lt;!x/y/z/).*};
  }
  
  __DATA__
  x/y/z/a/b/x.cc
  x/y/z/a/b/x.cc
  x/y/z/a/b/x.cc
  x/y/a/b/m.cc
  x/y/a/b/m.cc
  </code></pre>
  
  <p>My expectation is it would print only the bottom two strings, but it prints everything. But when I change the pattern to <code>(?&lt;=x/y/z/).*</code>, it is printing only the top 3 strings:</p>
  
  <pre><code>x/y/z/a/b/x.cc
  x/y/z/a/b/x.cc
  x/y/z/a/b/x.cc
  </code></pre>
  
  <p>Why so, and what should I do to fix my regexp?</p>