use strict; use XML::Twig; my $file = "bin/Example.xml"; my $node = $ARGV[0]; my $value = $ARGV[1]; my $count = 0; open(INDEX, ">bin/Index.txt"); my $twig = XML::Twig->new( start_tag_handlers => { Record => \&Count }, twig_roots => { $node => \&Record } ); $twig->parsefile($file); $twig->purge; sub Count { my ( $twig, $element )=@_; $count++; $twig->purge;} sub Record { my ( $twig, $record )=@_; if($record->text eq $value) { print INDEX $count."\n"; } $twig->purge; }