$VAR1 = { '27069_1' => { 'stop' => 214601666, 'start' => 214600991 }, '14644_1' => { 'stop' => 166950686, 'start' => 166950125 }, } #### $tss{$ch[0]}{$id}={ start=>$start, stop=>$stop }; #### 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