#!/usr/bin/perl use warnings; use strict; use Path::Tiny; setup(); # This is the solution: for my $file (path('test1')->children) { $file->copy('test2') unless path('test2/' . $file->basename)->exists; } sub setup { my %structure = ( test1 => [qw( abc.txt xyz.txt )], test2 => [qw( abc.txt sdf.txt fgh.txt )], ); my $i = 0; for my $dir (keys %structure) { for my $file (@{ $structure{$dir} }) { path("$dir/$file")->touchpath->spew($i++); } } }