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