open(HTML,"test.html") || die "cant open file\n"; while(){ if(//i ... /<\/body.*?>/i){ print OUTFILE $_; } } close HTML;