in reply to Parsing file and removing a section

($^I,@ARGV)=('.bak','file.txt'); while(<>){ my $c=$_=~/<VirtualHost.*>/..$_=~m!</VirtualHost>!; print unless $c; if($c==2){($ServerName)=/ServerName (.*)$/} }
Something like that might help...