Filehandle STDIN reopened as STDOUT only for output at ex.pl line 36 (#1) (W io) You opened for writing a filehandle that got the same filehandle id as STDIN. This occured because you closed STDIN previously.