my $twig= XML::Twig->new( twig_roots => { Hit_num => 1 } ); $twig->parsefile( $file); my @hit_nums= $twig->root->children; # do stuff with the Hit_num's #### my $twig= XML::Twig->new( twig_roots => { Hit_num => \&hit_num } ); $twig->parsefile( $file); sub hit_num { my( $t, $hit_num)= @_; # do stuff with the hit_num # $t->purge will free the memory if you don't need # to keep the hit_num around } #### my $twig= XML::Twig->new( twig_roots => { Hit_num => sub { hit_num( @_, $state_info); } } ); # ... sub hit_num { my( $t, $hit_num, $state_info)= @_;