Perl Telnet cisco routers

Hi all

i have little problem finding solution about simple telnet script .... i have 250 routers and on some i have different password and on some they ask just for password no username. So for example 1,2,3 have username and password (user,password) 4, and 5 have different username and password 6,7 have just password .... so i need a simple solution about this. Im new to perl but im learning now.

here is what i have for now ...

use Net::Telnet::Cisco;

for ($i = 1; $i <= 250; $i++){
$device = "10.10.$i.1";

  my $session = Net::Telnet::Cisco->new(Host => "$device",
										Input_log => "perllogrouter/router$i.log",
										);
   $session->login('admin', 'admin');
 
  # Execute a command
  $session->cmd('conf t');
  $session->cmd ('some command');
  $session->cmd('exit');
    $session->cmd("copy running-config "
						. "startup-config\n");  
 
  $session->close;
    
  }

And if you have some other solution pleas shear it, i relay need this ....