sub get_html_filename{ use Net::SFTP::Foreign; use File::Basename; use Cwd; use 5.01; my $sftp = shift; # get working directory my $dir = getcwd(); my $word = basename($dir); say "word is $word"; # get files from /pages my $ls = $sftp->ls("/pages", wanted => qr/$word/) or warn "unable to retrieve ".$sftp->error; print "$_->{filename}\n" for (@$ls); my @remote_files = map { $_->{filename} } @$ls; say "files are @remote_files"; my $rref = \@remote_files; my $filetype = "html"; my $old_num = highest_number($rref, $filetype, $word); print "old num is $old_num\n"; my $new_num = $old_num + 1; my $html_file = $word.$new_num.'.'.$filetype; return $html_file; }