You are better off using Expect/TCL to manage an ontape session. Expect is
a rule based scripting language built over TCL which is designed for
controlling equipment and other software.
Alternatively, my ALARMPROGRAM utility manages sessions of ontape in 'C'.
It includes a response parser to read the prompts from ontape and reply.
To do this in Perl you will have to run ontape as a pipe. Read the prompts
from the read side of the pipe and reply accordingly writing to the write
side of the pipe. You'll have to handle the possibility that ontape may not
prompt you and your script will hang until the ontape completes and the pipe
closes returning an error or use the poll() or select() system calls with a
timeout. This is easier in Expect which can run the pipe asynchronously.