#! perl use strict; use warnings; use v5.010.000; # enable "say" and other stuff use XML::Twig::XPath; use Data::Dumper; # for checking data structures my $t = XML::Twig->new( pretty_print => 'indented', twig_roots => { 'work' => \&fetch }, ); sub fetch { my ( $t, $work ) = @_; my %data; # limit actions to "" if ( exists $work->{att}->{eu} ) { # hopefully only one root within "" my $root = $work->first_child('root'); # save attribute data in hash %data %data = %{ $root->{att} }; # work with hash %data do_your_math( %data ); } } sub do_your_math { my %data = @_; # show content of %data print Data::Dumper->new( [ \%data ], [ '*data' ] )->Dump(); } $t->parseurl("http://arenas.pagesperso-orange.fr/divers/find.xml");