#!/usr/local/bin/perl -w use strict; sub find_holes { my @list = @{ shift() }; @list = sort { $a <=> $b } @list; my $low = $list[0]; my $high = $list[-1]; my %isthere = map { $_ => 0 } ($low..$high); $isthere{$_} = "yes" for @list; my @vacancies = grep { not $isthere{$_} } sort keys %isthere; return \@vacancies; } my @foo = qw(1 2 5 6 9); my $vac = find_holes(\@foo); print "@$vac\n"; __END__ $ ./holes.pl 3 4 7 8