Can I use perl to run a telnet or ftp session?

Try the Net::FTP and TCP::Client modules (available from CPAN). CPAN/scripts/netstuff/telnet.emul.shar will also help for emulating the telnet protocol.