use strict; use warnings; use File::Slurp; my $countfile = 1; open (IN, 'C:\terms.txt'); my @terms = ; close IN; open (OUT,'>>C:\result.txt'); while ($countfile < 10000) { my $text = read_file('C:\file' . $countfile . '.xml') or die "Can't open file!"; if($text =~ /upperboundary(.+?)lowerboundary/s){ if(grep {$_ eq $1} @terms) { print OUT "$1\t"; } } close IN; $countfile++; open (IN, 'C:\file' . $countfile . '.xml') or die "End of files!"; } close OUT;