# read XML file in $xml_string my $out=''; while($xml_string=~s!^(.*?\s*)(<\?xml.+?>)(\s*)!!s){ $out.=$1.'\E/]]]>/gs; $out.=$in.']]>'.$after; } $xml_string=$out.$xml_string; $out=''; # parse XML $xml_string ...