use strict; local $/;#####To read the whole content of a file while(){ while($_=~/\(\!-- #BeginEditable \"([^"]*)" --\)(.*?)\(\!-- #EndEditable --\)/sgi){ print "IN:$1:$2\n"; ##do your stuffs here } }