while (my $line=<$tfh>) { chomp $line; my ($id, $title, $abs)=split /\|/, $line; my @sentences=split /\./, $abs; print $ofh "$id|"; for my $idx (0..$#sentences) { print $ofh '<', $idx+1, '>'; for my $word (split ' ', $sentences[$idx]) { if ($words{uc $word}) { print $ofh "$word " } else { for (sort keys %words) { if ($words{$_}{uc $word}) { print $ofh "mainterm:$_:matchedterm:$word "; last; } } } } } print $ofh "\n"; }