sub consecutive_array { return scalar ( $_[0]..$_[-1] ) && # option: ! grep { /\D/ } @_ && # checks for digits only join "_", @_ eq join "_", ($_[0]..$_[-1]); } #UPDATE, need to sort this array too to work, oops :-) my @bigarray = sort map { ( $_->{array} ) } keys %hash; my $valid = $bigarray[0] == 0 && consectutive_array( @bigarray ) && ! grep { !consectutive_array( $_->{array} ) } keys %hash;