#!/usr/bin/perl -w use strict; use File::Copy; my $source_dir = "C:/temp"; my $dest_dir = "C:/temp2"; move_pdf($source_dir, $dest_dir); sub move_pdf { my ($src_path, $dest_path) = @_; opendir (SOURCE_DIR, $src_path) or die "can't open sourcedir"; if (!-e $dest_path) { mkdir $dest_path or die "can't create $dest_path"; } my @pdf2copy = grep{/\.pdf$/} readdir SOURCE_DIR; foreach my $file (@pdf2copy) { copy ( "$src_path/$file", "$dest_path/$file") || die "copy failed $src_path/$file, $dest_path/$file"; } }