#!/perl use strict; use warnings FATAL => qw(all); use Text::CSV_XS; use XML::LibXML; my $csv_par = { binary => 1, auto_diag => 1, allow_whitespace => 1, sep_char => ';', eol => $/, quote_char => undef, }; my $csv = Text::CSV_XS->new($csv_par); my @header = @{$csv->getline(*DATA)}; my %rec; $csv->bind_columns(\@rec{@header}); my $doc = XML::LibXML::Document->new('1.0', 'utf-8'); my $root = $doc->createElement("ROOT"); print join("\n", '', ''),$/; while ( $csv->getline(*DATA) ) { my $line_tag = $doc->createElement("alpha"); $line_tag->setAttribute('name'=> $rec{"alpha"}); # $root->appendChild($line_tag); # intentional. for my $other ( qw(beta gamma) ) { my $other_tag = $doc->createElement($other); $other_tag->setAttribute(name => $rec{$other}); $line_tag->appendChild($other_tag); } print $line_tag->toString(1),$/; } print '',$/; =output =cut __DATA__ alpha;beta;gamma q;2;3 w;9;8 e;1;2 r;6;7 t;5;9 y;3;1