use strict; use XML::Twig; my $file = $ARGV[0]; my $first = 'paragraph'; my $replace = 'p'; my $twig = XML::Twig->new(twig_handlers => {"$first" => sub {$_->set_gi("$replace")}}, ); $twig->parsefile($file); $twig->print; #### Input: Société Nationale des Chemins de Fer Français, the Spain (Telefónica) Current Output:

Société Nationale des Chemins de Fer Français, the Spain (Telefónica)

Expected Output:

Société Nationale des Chemins de Fer Français, the Spain (Telefónica)