use strict; use warnings; use Sys::Hostname; chmod 0700, $0; my $remote_host = 'somewhere'; my $user_name = 'somebody'; my $password = 'something'; if ( hostname ne $remote_host ) { require Net::SFTP; require File::Basename; require Net::SSH::Perl; my $remote_file = basename $0; my $sftp = Net::SFTP->new( $remote_host, user => $user_name, password => $password ); $sftp->put( $0, $remote_file ); my $ssh = Net::SSH::Perl->new($remote_host); $ssh->login( $user_name, $password ); $ssh->cmd($remote_file); } else { unlink $0; # do your stuff here }