# Create connection my $SSH = Net:OpenSSH->( $IP, user => 'user', password => 'pass' ); if( !$SSH->error ) { # Is my process running? my $PROC = $SSH->capture( "ps aux | grep | grep -v grep | wc -l | sed 's/ *//'" ); if( $PROC == 0 ) { # 3rd party program is run here via perl system method # If it happens to fail, it has no adverse consequences on # the rest of the script. if( ) { # Read File on remote machine ( $DATA, $ERR ) = $SSH->capture2( "cat # Delete the remote file $SSH->system( "rm -f " ); # And finally, since my remote process is not currently # running, spawn it on the remote machine $SSH-spawn( "./script.pl" ); } } } else { print $SSH-error }