use strict; use XML::Twig; my $file = "bin/Example.xml"; my $i; my $count = 0; my $data_file = "bin/Index.txt"; open(DAT, $data_file) || die("Could not open file!"); my @id=; close(DAT); my $twig = XML::Twig->new( start_tag_handlers => { Record => \&Check }, twig_handlers => { Record => \&Process } ); $twig->parsefile($file); $twig->purge; sub Check { my ($twig, $record)=@_; $i = 0; $count++; if ($count > $id[-1]){ $twig->finish_now;} my $thisId = $count."\n"; foreach my $id (@id){ if ($thisId eq $id){ $i = 1; last;}} if ( $i ne 1){ $record->ignore; } } sub Process { my ($twig, $record)=@_; # PRINT ALL NODES FROM RECORD HERE... $twig->purge; }