Very hard to offer meaningful help without the code that is failing but I'll try anyway. You need to check the data that you read in before assigning it to the array. The read could return a null record. Especially the last read in the file can return an undef. This is generally not a problem when you use the while(<FH>) construct because that is shorthand for while(defined($_=<FH>)) but if you use other read methods you have to call defined() yourself.
s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s
|-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,,
$|=1,select$,,$,,$,,1e-1;print;redo}