in reply to [SOLVED]open to read file, erases all my files

Several things puzzle me about this. The first is your post title, which implies there is a problem with stdin. What makes you think that erasing files is connected with stdin in anyway? By the way, none of the code shows stdin being used.

Behaviour of file IO is operating system dependant, although judging from your mention of rm -r I guess you are working with some sort of UNIX or Linux. Opening a directory for write on such platforms should return error EISDIR (is a directory), although opening for read is allowed.

So, what ways can the files be erased? I'm guessing you do not have anything as blatent as unlink glob('dir/*'); or an opendir/readdir/closedir loop.
However there can be some confusion surrounding the < thing > notation in Perl, in that it can mean a glob construct, or it can mean a read from a file handle. Maybe worth checking your syntax on such instructions.

It sounds that the entire directory list is being erased somehow, but, thinking out of the box, maybe the files were renamed? A dot '.' prefix to the filename would effectively hide the files, so ls -a might be worth a go.

Other than that, run the program under strace(1) or truss(1) to see the kernel calls.