in reply to Faster Flat File

Any help, guidance or enlightement that may be offered will be greatly appreciated.

First, where is the $fa in   if ($m =~ /$fa/g){ coming from? The shape of the code suggests that you may have meant to use $f, instead. (If you note already using strict, please consider doing so. It saves a lot of minor typo grief.)

For faster access to the file, your OS may provide some exploitable capabilities. If you're running on a *nix system that includes shared memory, you can slurp the file into shared memory. I might be marginally faster to access it from there, since you can bypass the overhead of openning the file.

As your file grows, linear scans get more expensive. The typical way around this is index the file so that you don't need to read the entire thing to find the pieces you're looking for. Unfortunately, by using regexs to score hits, you make indexing difficult.

Is   if ($s =~ /$d/g){ really how need want to work that comparison? Depending on your data, it could give you a lot of false hits. If the intent is to match a search term $s if it is a word in $d, then   if ( $s =~ /\b$d\b/i ) { is more accurate. That also puts you in a better position to build a search index from the individual words in $d.