in reply to problem of filehandling

What part of This occured because you closed STDIN previously. don't you understand? You do close STDIN two lines above it.

As for opening STDIN yourself, you could make use of the magic of the open command. If you open a file called "-", Perl will read from standard input. For instance:

Getoptions (...); $input = "-" unless defined $input; open my $fh => $input or die $!; while (<$fh>) { ... }

Abigail