for my $checkhash ( keys %{ $sets{ $fasta_id }[ $setscounter ] } ) { unless( defined $sets{ $fasta_id }[ $setscounter ]{ $checkhash }[ 0 ] ) { undef $sets{ $fasta_id }[ $setscounter ] }; last; } } if( scalar keys %{ $sets{ $fasta_id }[ $setscounter ] } < $num ) { undef $sets{ $fasta_id }[ $setscounter ]; } $setscounter++ if scalar %{ $sets{ $fasta_id }[ $setscounter ] }; } } if( @{ $sets{ $fasta_id } } ) { pop @{ $sets{ $fasta_id } } unless scalar %{ $sets{ $fasta_id }[ $#{ $sets{ $fasta_id } } ] }; }