#!/usr/bin/perl use strict; use warnings; my @array = (1,2,3,6,4,5,7,8,9); # UPDATED again, numeric sort my $smallest = (sort {$a <=> $b} @array)[0]; my $stored = shift @array; # UPDATED per bug report in reply # if ($stored != $smallest) { if ($stored != $smallest && $stored + 1 != $array[0]) { print "$stored appears to be in the wrong position\n"; exit; } foreach my $i (0 .. $#array) { if ($stored != $array[$i] - 1) { if ($array[$i] + 1 != $array[$i + 1]) { print "$array[$i] appears to be in the wrong position\n"; last; } } $stored = $array[$i]; }