in reply to check which files are open to write/read by another process

Since you can get into a whole mess of conditions that are difficult to anticipate (e.g. security, filesystem types, the phase of the moon ...), not to mention race conditions, I have found that the simplest way is simply to attempt to open the file, requesting an exclusive access-mode if you can.

Wrap the whole thing in an eval{} block, then test the error-variable ($@) to see if it has a non-empty value.   Also check that the return-code and so forth, but do both.