#### use strict; use warnings; use XML::Twig; my $out_file = 'C:\web_bu.xml'; my $t = XML::Twig->new( twig_handlers => {'display-name' => \&convert}, pretty_print => 'indented' ); $t->parse(*DATA); open (my $fh_out, '>', $out_file) or die "unable to open '$out_file' for writing: $!"; $t->print($fh_out); # this prints to the filehandle sub convert { my ($t, $elt) = @_; my $txt = $elt->text(); if ($txt =~ /wtw_reports/i) { $elt->set_text('SOMEGUY'); } }