# open intermediate file for pass of XML file open (INTFILEout, '>', $intfile) or die ("Cannot open file $intfile") unless -f $intfile; # parse thru XML file into intermediate file my $parser = new XML::Parser; $parser->setHandlers( Start => \&startElement, End => \&endElement, Char => \&characterData, Default => \&default); $parser->parsefile($xmlfile); # close intermediate file from first pass of XML file close INTFILEout; # reopen intermediate file for load into formatted output file open (INTFILEin, '<', $intfile) or die ("Cannot open file $intfile") unless -f $intfile; open (FMTFILE, '>', $frmtfile) or die ("Cannot open file $frmtfile") unless -f $frmtfile; # processing intermediate file into formatted file while ($linein = ){ chomp $linein; print FMTFILE "$linein\n"; } # close files used to create formatted file close INTFILEin; close FMTFILE;