Adding use strict; at the beginning of your script (and fixing everything it subsequently complains about) would likely have pointed you directly at the problem.
in reply to How to print list using Net::SFTP::Foreign
According to Net::SFTP::Foreign, $sftp->ls($remote, %opts):
Returns a reference to a list of entries. Every entry is a reference to a hash with three keys: ...Thus, your
should not have the @ in front of $remotefiles.
# List remote directory contents