open( TRANSLATIONS, $translations_file ) or die "Could not open '$translations_file': $!"; while( ) { if( my ($word, $translation) = split /\|/ ) { push( @translations, { match => qr/\b$word\b/i, replacement => $translation, } ); } } close( TRANSLATIONS ); my $twig= new XML::Twig( twig_handlers => { 'FOO' => \&foo }, pretty_print => 'indented', output_filter => 'safe', ); $twig->parsefile( $xml_file ); $twig->print;