#!/usr/bin/perl -w use strict; use XML::Twig; my $file = "/Users/mem/Desktop/CV/test.xml"; my %cities; my $twig = XML::Twig-> new( KeepEncoding => 1, TwigRoots => {'europe' => 1}, TwigHandlers => {'capitale[@lang="fr"]' => sub {$cities{$_[1]->text} = $_[1]->att("lang")}} ); $twig-> parsefile($file); $twig-> purge; foreach my $key (keys %cities) { print "$key = $cities{$key}\n"; }