use XML::Writer; use XML::Reader; use IO::File; open(FH,"./input.txt"); #open the input file my $input; my $output = new IO::File(">converted_to_xml.xml"); #file to write the converted content my $writer = new XML::Writer(OUTPUT => $output); #write into the opened file my @array=qw(name emp_no designation salary); while($input=){ #Read the input line from the file chomp($input); #remove the newline character my($name,$emp_no,$designation,$salary)=split /:/, $input; #split the input by comma character $writer->xmlDecl("UTF-8"); #XML declaration foreach my $val(@array){ $writer->startTag("$val"); #Starting tag my $var="\$".$val; $writer->characters(eval("$var")); #Character data in an XML document $writer->endTag("$val"); } } $writer->end(); $output->close();