You could do it in perl, but you might find it easier to just use something already on most (all?) *ix systems:
somecommand 2>&1 | tee logfile
Try
man tee for more information.
update: I realized this answer is a bit terse and
doesn't really answer the question. If you are actually looking for how to do it in perl, you will have to intercept output from the scripts (send that both to a file and to STDOUT), and the user's input, which will have to be passed along to the script. This can get tricky, expecially if your program doesn't know what should happen next (should it look for output from the script you just ran, or input from the user next?), but IPC::open2/open3 or Expect.pm can do what you want.