for(keys(%the_hash)){ my $ch=$_; my @a=keys(%{$tss{$ch}}); my $tid=pop(@a); my $s=$tss{$ch}{$tid}{'start'}; my $st=$tss{$ch}{$tid}{'stop'}; foreach(keys(%{$tss{$ch}})){my $k=$_; if($tss{$ch}{$k}{'start'} eq $s and $tss{$ch}{$k}{'stop'} eq $st #and $_ ne $tid ){ delete($tss{$ch}{$k}); } ..... and so on