my $dirs = $sftp->ls(...); my @sorted = sort {$a->{a}{mtime} <=> $b->{a}{mtime}} @$dirs;