hosts.csv data: R17N6340-C04-1;10.1.70.1 R17N6340-C04-2,10.1.70.2 R17N6340-C04-3,10.1.70.3 #!/usr/bin/perl #use strict; #use warnings; my $xml_file = 'template.txt'; my $list_file = 'hosts.csv'; my $out_file = 'newhost.xml'; # open( XML, '<:utf8', $xml_file ); open( LIST, '<:utf8', $list_file ); open( OUT, '>>:utf8', $out_file ); my $xml; { local $/ = undef; $xml = ; }; my $line; foreach $line ( ) { # Skipping if the line is empty or a comment next if $line =~ /^\s*$/ ; next if $line =~ /^\s*#/ ; my ($hostname, $interface) = split(/,/, $lin); $xml =~ s/hostname/$hostname/g; $xml =~ s/interface/$interface/g; } print XML $xml; close