in reply to Help Using Magic Script

There are many identical lines in your code. Consider using a sub with a parameter telling it to use either telnet or ssh. (See Copy and paste programming)