my $file_put = 0; foreach my $file (@file_globs){ foreach my $filepath (glob($local_dir.$file)) { next if (! -e $filepath); $filename = $filepath; #strip down file path to just get file name $filename =~ s/(.*\/)//; $sftp_connection->put($filepath, $remote_dir.$filename); if ($sftp_connection->error == 0){ &logEntry($args{'logfile'}, "$jobname--Putting remote file: /".$remote_dir.$filename); $file_put = 1; } elsif ($sftp_connection->error != 0){ &logEntry($args{'logfile'}, "$jobname-ERROR: ".$sftp_connection->error); } } }