# Get list of remote files my @remote_files= qx(ssh $uid $h 'find $dirname'); #### # Munge filenames to commands: my @commands= map { sprintf "mv -i '%s' '%s.bak'", quotemeta($_), quotemeta($_) } @remote_files; #### # Send list of commands to the remote side: # First, a dry-run instead of actually doing that: my $remote= \*STDOUT; # Use this to actually do the remote execution: #open $remote, "| ssh -q -l $uid $h"; print { $remote } join "\n", @commands;