foreach my $file (@files){ # set up the XML parser: my $twig= XML::Twig->new( twig_handlers => { topicref => \&topicref_processing, xref => \&topicref_processing }, ); $twig->parsefile($file); $twig->purge; } #### sub topicref_processing { my($twig, $topicref) = @_; my($atts) = $topicref->atts(); if($$atts{'keyref'}){ ### associate this keyref with $file } }