use strict; ## I've lazily pre-sorted these ;) my @ars = ( [ qw/ 1 2 3 4 5 / ], [ qw/ 1 2 3 4 6 / ], [ qw/ 2 3 4 6 7 / ], ); for(@ars) { print "broken list: @$_\n" and next if $_->[0] != 1; my($i, $n) = 0; $n = $_->[$i] while $i <= $#{$_} and $_->[$i] + 1 == $_->[++$i]; print "woo: @$_\n" if $n == $_->[-1]; print "doh: sequence broke at index ${\($i - 1)} (@$_[$i - 1,$i])\n" if $n != $_->[-1]; } __output__ woo: 1 2 3 4 5 doh: sequence broke at index 3 (4 6) broken list: 2 3 4 6 7