I prefer seeing parentheses there. You don't actually
need them, but I write them anyways. Besides which, if
you aren't in the habit of writing them, it is too easy
for someone copying you to decide they like writing or
as || and not know they are losing the error check.
Speaking of the error check, you aren't testing $!.
If you are using a 3 argument open already so your
code documents what you are doing, then I like having
your error message say whether you are reading, etc.
Your factoring of work bothers me. Opening a file
and slurping it in are things you are likely to have to
write a lot. Slurping it just to scan the file is less
likely. So I would prefer to see a function to slurp
in the file and a separate one to scan through the slurped
in file. Then call one with input from the other. An
advantage to this arrangement is that your global is not
in an altered state while scan is being called...