#!/usr/bin/perl use warnings; use strict; my @values = qw( 11673326 11673329 11673325 11673330 11673321 11673335 ); my @sorted = sort { $a <=> $b } @values; sub next_higher { my ($from) = @_; for (@sorted) { return $_ if $_ > $from; } return } use Test::More; is next_higher(11673326), 11673329; is next_higher(11673335), undef; is next_higher(11673321), 11673325;