in reply to ssh system command

or using one of the SFTP client modules:
use Net::SFTP::Foreign; my $s = Net::SFTP::Foreign->new('apple1'); die "sftp connection failed: ". $s->error if $s->error; my @fn = $sftp->glob('/home/dist/*', names_only => 1); for my $fn (@fn) { my $data = $s->get_content($fn); if ($s->error) { warn "unable to read $fn: ".$s->error } else { print $data; } }
At first, it may seem more complex than a shell based solution, but if you need to change the functionality of your script later, or check for errors or anything else, having a full file system API at your disposal would help