Finally (for now), you use this construct: %{ $sets{ $fasta_id }[ $setscounter ] } = (); To empty arrays in several places. Whilst there is nothing wrong with this, I think it is clearer, and may be slightly quicker to use undef $sets{ $fasta_id }[ $setscounter ] };