my $twig= XML::Twig->new( twig_handlers => { topicref => sub{ topicref_processing(@_, $filename);}, ); sub topicref_processing{ my($twig,$elt, $filename)=@_; ####you can get twig and elt here. }