Perl: find next available lowest number that is available in two arrays

Hi there. I have a number allocation problem whereby I have 2 arrays built from 2 different sources. The arrays will just contain a listed of sorted numbers

@a 

1
7
10
14
15
16

@b

1
7
10
11
14
15
16

i need to scan both arrays and find the lowest available number that is available in both arrays that is higher than $min which is set to "10". once it finds the the lowest unused number, it quits and presents it in a variable

So in the case of the two arrays above, the number that would get presented is 12 (as 11 is used in one of the arrays)

I have been trying various things such as setting a counter and looping through the two arrays but have been getting myself in a real pickle of infinate loops and utter mess

I wanted to ask whether anyone could point me in the right direction on the best way to tackle this one?

any advice or guidance would be greatly appreciated

Thanks

This is one way, Check out the below example:

my $min        =  10;
my $max        =  999;
my $s          =   0;
my @array1     =  qw/1 7 10 14 15 16/;
my @array2     =  qw/1 7 10 11 14 15 16/;
my @array3     =  ( @array1, @array2 );
my %hash;

@hash{@array3} =  ();

$s  =  ++$min;

while ( $s <= $max ) {
  if ( ! exists $hash{"$s"}) {
    print "Available: $s\n";
    last;
  }
  $s++;
}

thanks that is a great starting point, much appreicated :smiley: