my $f = $sftp->ls('/xxxx/xxxxx/outbound'); # $f instead of @files #removed a loop here foreach my $file_ref ( @{$files} ) {