while () { if(/=begin/) { read the next line. check whether the line is "=end" or not... If it "=end" stop the read operation. Otherwise continue the read process. } }