in reply to my xml xpath is too slow.

Wouldn't it be easier to write it (and read it) this way?:

use strict; use XML::Parser; use XML::XPath; use Lingua::StopWords qw( getStopWords ); my $stopwords = getStopWords('en'); my $file = $ARGV[0]; my $xp = XML::XPath->new(filename=>$file); for my $n(1..600) { my %seent; my $textnodeset = $xp->find('//pair[@id = '.$n.']/tAnnotation/tree +/node/word/attribute[@name="token"]'); my @texts = map $_->string_value, $textnodeset->get_nodelist; my @termst = grep{!$seent{$_}++ && !$stopwords->{$_}} @texts; my %seenh; my $hyponodeset = $xp->find('//pair[@id = '.$n.']/hAnnotation/tree +/node/word/attribute[@name="token"]'); my @hypos = map $_->string_value, $hyponodeset->get_nodelist; my @termsh = grep{!$seenh{$_}++ && !$stopwords->{$_}} @hypos; for my $i (@termst) { for my $j (@termsh) { print "$i $j\n" } } }

You could search google for 'xpath unique', so that xpath returns only unique values. But I am not sure if it will speed things up or slow them down...