while () { s/\s#.*//; next unless /\S/; do_something($_); } __DATA__ # This is my file # with a few lines of comments data=here # another comment more=data # more comments and=more # end of file