use File::Copy; use File::Basename; for $base (map basename $_, map glob "$_/*", @ARGV) { my ($src, $dst) = map "$_/$base", @ARGV; -f $src and not -e $dst and not copy $src, $dst and warn "copy $src to $dst failed"; -f $dst and not -e $src and not unlink $dst and warn "unlink $dst failed: $!"; }