if($text =~ /upperboundary(.+)lowerboundary/s){ if(grep {$_ eq $1} @terms){ print OUT "$1\t"; } }