open(my $outFH, '>', "out.xml"); while (<>) { ...; $csv_obj->print_xml($outFH); }