use warnings; use strict; use File::Find; use File::Spec::Functions; use Time::HiRes; use File::Copy; my $root = "/path/to/root" find(\&wanted, $root); sub wanted { if (File::Find::dir eq $root) { print "$_ is already in the root folder $root\n"; } else { my $target = catfile($root, $_); if (-f $target) { my $microtime = join '.', Time::HiRes::gettimeofday(); print "Filename collision, appending $microtime to $_ before moving\n"; move($File::Find::name, $target . $microtime); } else { print "Moving " . $File::Find::name . " to $target\n"; move($File::Find::name, $target) } } }