#!/usr/bin/perl -w use strict; use warnings; use File::Copy; opendir( RS, "seqresults/resultsdate"); my %rs; while (defined($rs = readdir (RS))) { @rs_info = split(/_/,$rs); my $idnum= $fields[0]; if ($count == null){ ${maid}=1; }else{ ${maid}=$count+1; } foreach my $maid ( keys %h ){ if ($h{$maid}==4){ #call routine to do your copy logic } } } closedir RS; opendir( SA, "/newdir/");