#!/usr/bin/perl use strict; use warnings; use XML::Twig; my $name_file='names.txt'; my $data_file='data.xml'; my $outp_file='data.out.xml'; my %replace; open(my $nfh, '<', $name_file) or die "error open $name_file $!\n"; while(my $line=<$nfh>) { chomp($line); $replace{$1}=$2 if($line=~/^\s*(.+?)\s*=>\s*(.+?)\s*$/); } close($nfh); my $twig=XML::Twig->new( pretty_print => 'cvs', twig_handlers => { _all_ => sub { $_->set_text($replace{$_->text}) if(exists($replace{$_->text})) } } ); $twig->parsefile($data_file); open(my $ofh, '>', $outp_file) or die "error open $outp_file $!\n"; $twig->print($ofh); close($ofh);