use File::Copy; use File::Spec::Functions qw(catfile); use constant SRCDIR => '/tmp/src'; use constant DESTDIR => '/tmp/dest'; my @file = do { opendir my($dirh), SRCDIR or die $!; readdir $dirh; }; while(@file > 2) { my $tomove = splice @file, (-M $file[0] < -M $file[1] ? 1 : 0), 1; move(catfile(SRCDIR, $tomove), catfile(DESTDIR, $tomove)); }