#!/usr/bin/perl use strict; use warnings; use XML::Twig; my $twig= XML::Twig->new( TwigHandlers => { "eSearchResult/IdList/Id" => \&id_Tag } ); $twig->parsefile("bla.xml") or die "cannot parse : $!"; sub id_Tag { my($t, $idTag)= @_; print $idTag->text(), "\n"; # Release memory of processed tree up to here $t->purge(); }