Try replacing
$count++ while $text =~ /$gene/g; # Count number of instances
with
my $patn = qr/\b$gene\b/;
$count++ while $text =~ /$patn/g;
In reply to Compile the regex
by arunp
in thread speeding up regex
by dannoura
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |