There is one cpan option "inactivity timeout", preventing cpan from waiting forever, but it won't help you much here. Are you creating a script for a spesific installation job, or for the general case? If the first, then Expect might help.
Actually, Expect might be good in the general case too.