while(){ if ( /^-- start foo/ .. /^-- end foo/ ){ # do what you like to do here } }