my @contents = $sftp->ls($RemoteBaseDirectory . $RemoteOutgoingDirectory); my @sorted = sort {$b->{a}->mtime <=> $b->{a}->mtime} @contents; print $sorted[0]->{longname};