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