in reply to file copy undefined?

undefined subroutine &main::Copy

File::Copy exports a sub named copy, not Copy.

$ perl -le'use File::Copy qw( Copy ); print "ok"' "Copy" is not exported by the File::Copy module Can't continue after import errors at -e line 1 BEGIN failed--compilation aborted at -e line 1. $ perl -le'use File::Copy qw( copy ); print "ok"' ok

global symbol $_ requires explicit package name

Well, you won't get that error for $_ specifically — it's special — but it's correctly claiming that you didn't declare any of your other variables.

... my $dirpath=... ... while (defined (my $file = ...) ) { ... foreach my $filename (...) { ... } ...