#! perl -slw use strict; use Data::Dump qw[ pp ]; my %tss = map { my $s = int( rand 1000 ); $_ => { start => $s, stop => $s + int( rand 100 ) } } 1 .. 100; #pp \%tss; my @ids = sort{ $a <=> $b } keys %tss; my @toDelete; for my $first ( 0 .. $#ids ) { for my $second ( $first+1 .. $#ids ) { ## updated per NetWallah's suggestion below push( @toDelete, $ids[ $first ] ), last unless $tss{ $ids[ $first ] }{ start } > $tss{ $ids[ $second ] }{ stop } or $tss{ $ids[ $first ] }{ stop } < $tss{ $ids[ $second ] }{ start }; } } #pp \@toDelete; delete @tss{ @toDelete }; pp \%tss; __END__ C:\test>junk { 74 => { start => 982, stop => 1011 }, 80 => { start => 572, stop => 577 }, 87 => { start => 286, stop => 319 }, 90 => { start => 600, stop => 674 }, 91 => { start => 252, stop => 266 }, 92 => { start => 1, stop => 7 }, 94 => { start => 210, stop => 221 }, 95 => { start => 553, stop => 554 }, 96 => { start => 113, stop => 158 }, 97 => { start => 752, stop => 820 }, 98 => { start => 543, stop => 550 }, 99 => { start => 436, stop => 456 }, 100 => { start => 696, stop => 725 }, }