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