opendir DIR, "DIR_A"; while(defined(my $item = readdir DIR)){ open FILE,"DIR_A/$item" or warn "$!", next; open COPY,"COPIES/$item" or warn "$!", next; while (read FILE,my $buffer,4096){ print COPY $buffer; } close FILE; close COPY; exec("mv","DIR_A/$item","DIR_B/$item"); # performes an mv command like on the command line } closedir DIR;