foreach my $remote_in_dir (@remote_in_dir_list) { my $arrayref; # ftp returning an undef in scalar context is so not useful. do { $arrayref = $ftp->dir("$remote_dir/$remote_in_dir"); # This kills more than the current operation # Could be a local problem, need to try a different server. $ftp->_ABOR unless $arrayref; } until $arrayref; $file_list{$remote_dir}{$remote_in_dir} = $arrayref; . . . }