foreach my $k (keys(%files)){ print "$k\n"; #get the array from the array reference. #See how the reference gets in the has below. my @arr=@{$files{$k}}; print "Size: ",scalar @arr,"\n"; print "Max Index: ", $#arr,"\n"; #skip unless we have 4 files in the array next unless ( scalar my @array) == 4; #look for KOMP maid directory we want to copy to #glob dirs with a regex something like /$k\D/ - lets call it $KOMP_dir $komp_dir = maid_dirs($maid); #Create the sequencing sub dir under $KOMP_dir #so now KOMP_dir=KOMP_dir+"/sequencing" mkdir $komp_dir."/seqeuncing/"; $komp_dir=$komp_dir."/sequencing/"; print "$komp_dir\n"; #now iterate through the array, copying the files. You know the maid number ($k) foreach my $f(@arr){ copy("$f","$komp_dir.$f"); print "copying $f to $komp_dir\n"; }