You probably want to be using the system command instead of using backticks. Backticks capture the output of the command and return it to the Perl program. The system command, however, goes off and executes the program, returning the exit value to the Perl program. That seems to be what you want for the if condition, where you're checking for a return value of 0 (successful exit). For the ssh command inside the if block, maybe take a look at the exec command. It starts the given command, replacing the running Perl program, which it kind of looks like you want to do. Maybe give us a better idea of what the intended operation of your program is and we can help a bit more.
Perl6 Grammar Student