my $t = new Net::Telnet(..) || branch(args); #code to occur if the telnet session is established. exit; sub branch { #code here and bail out exit; }