I'm guessing based in your data, that your numbers are sequential, but wrapping around 100. So you would find the 'start' by ordering everything, then looking for the gap. (This breaks if you have a complete cycle though!)
#!/usr/bin/env perl
use strict;
use warnings;
my @numbers = ( 1,2,3,4,5,97,98,99 );
#sort them
my @sorted = sort { $a <=> $b } @numbers;
#rotate the numbers until your 'gap' is off the end of the cycle.
my $splice = 0;
for ( my $index = 0; $index < $#numbers; $index++ ) {
print 1+$sorted[$index] % 100,",";
print $sorted[$index+1] % 100,"\n";
if ( ($sorted[$index] + 1 ) %100 < $sorted[$index+1] % 100 ) {
$splice = $index;
}
}
print "Splicing on $splice\n";
@numbers = ( splice ( @sorted, $splice+1, @sorted - $splice ), splice ( @sorted, 0, $splice+1 ) );
print join ",", @numbers;
Edit: OK, new test cases. Might not work for those. Hopefully this illustrates an approach. But with gaps in your ordering (I have assumed no gaps) it's very hard to tell because you're basically looking for the biggest gap.