in reply to regex: finding something followed explicitly by a dot

You have a quotemeta problem, a dot (for one) is special in regexes. Replace
if($filecontents =~ /$word/smg) {
with
if($filecontents =~ /\Q$word/smg) {
and now you can do literal searches.