use strict; use warnings; use File::Spec::Functions qw/catfile/; my $dirnameto = catfile(qq{pr book}); my $dirnamefrom = catfile(qq{pr perl_by_example}); opendir( $dhandlefrom, $dirnamefrom )or die; while (my $file=readdir($dirhandlefrom)) { next if $file =~ /\./; my $filecontents; {local $/ = undef; # slurp mode; open( my $tfh, '<', catfile( qq{$dirnamefrom $file} ) ) or die; $filecontents = <$tfh>; close $tfh; # for clarity; } open( my $filecopy, '>', catfile( qq{$dirnameto $file} )) or die; print { $filecopy } $filecontents; close $filecopy; }