in reply to readline on closed filehandle error

Cut your code down to a minimal (preferably 15 lines or less), compliable script which reproduces the problem. At that point, you have a far better chance that the (busy) Monks will be able to take the time to help...

... and, in doing so, you may well discover why the 317 line versions fails. This is way too much code for a very basic question.

But, in the interest of demonstrating our desire to help you learn, you should modify your code to test the open at 137. Instead of

open (I16S,"$in16S");

test the open (and specify that you are opening for a read):

open (I16S, "<", "$in16S" or die "Can't open $fh for read: $!;"

And while you're at it, look at using variables instead of raw filehandles; e.g., $fh as the first element insde the parens) and (perhaps; as I said, 300+ lines is too much of a burden) use a meaningful name for the var, $in16S.