How to answer the Questions in Perl .

I need to write a script to telnet or ssh a device the execute some commands in device then copy the output in a file, I wrote the script but I faced one issue, when you execute some commands the device asked me a Question, for example :
device # copy run tftp
device # Source filename [running-config]?

then the script hang, my Question is how to pass the answers to device using perl ??

Google "here document in perl".

If you are using shell you can use a here document too, or use the yes command and pipes. yes "answer" |"command expecting answer".

You can give yes multiple answers, like yes "y y y" |...

Thanks a lot for your reply
May you please explain me more with examples,
This is my telnet script :

#!/usr/local/bin/perl
$ip       = $ARGV[0];
die ("IP must be passed as an argument. $!\n") unless defined($ip);
use Net::Telnet ();
$handle = new Net::Telnet (Timeout => 10, Prompt => '/.*(#|>|\))\s*$/');
$handle->open("$ip"); 
$handle->login("Username","password");
$handle->cmd("terminal length 0");
@lines = $handle->cmd(" ANY COMMAND HERE NEED ANSWER");
print "@lines";
$handle->cmd(exit);
$handle->close;

any help :frowning: