use CAM::PDF; use File::Copy; #Initialize title page pdf my $doc1 = CAM::PDF->new("$file1") || die "$CAM::PDF::errstr\n"; #Read each pdf file on the desktop opendir(DIR,$directory); my @files = grep{/\.pdf$/}readdir(DIR); closedir(DIR); #Get the names of all the files. foreach(@files[0]){ $name2=$_; $file2="$directory"."$name2"; $doc2 = CAM::PDF->new("$file2") || die "$CAM::PDF::errstr\n"; #Append the thermogram file with each document $doc1->appendPDF($doc2); $doc1->clearAnnotations(); $doc1->cleanoutput("$file1"); #Move each file to the destination folder $file3="$destination"."$name2"; move("$file2","$file3") || die "Move failed: $!"; $file2->close || die "Source file failed to close: $!"; $file3->close|| die "Target file failed to close: $!"; }