if the target is a Unix box, you could use
Net::Telnet
We used this as the basis for remotely provisioning and controlling about 4000 Netscreen appliances before
Net::Telnet::Netscreen came out.
It's pretty easy to use as you can see from the example provided.
use Net::Telnet ();
$t = new Net::Telnet (Timeout => 10,
Prompt => '/bash\$ $/');
$t->open("sparky");
$t->login($username, $passwd);
@lines = $t->cmd("who");
print @lines;
You might have to make some adjustments for the prompt returned, but the documention provides examples for this as well.
Of course, if you aren't connecting to something that will accept a Telnet session, such as a winblows box....all bets are off for this example.