perl -ne 'print if !/^#/ and /foo/' /tmp/foo.txt #### perl -ne 'print if /^[^#]*foo/' /tmp/foo.txt