in reply to Check whether a file exists

You already defined your test cases in prose.

All you need to do now is to create the situations on the target machine in a safe environment and see what your code does.

print ">$grep<\n"; # see what $grep contains

Cheers, Sören