in reply to test if a scalar contains a filename or a filehandle?

if I'm reading it right using your code if a file exists with the same name as an open filehandle it will ignore the existing filehandle and open the file (which is not what you want). You should really test to see if the parameter is an already open filehandle. You can do this like so:
if (fileno $file_or_handle) { # $file_or_handle is a filehandle } else { # $file_or_handle is a file # test for existance and open }
the fileno() function returns the file descriptor for an open filehandle or it returns undef if the filehandle is not open.

John