#!/usr/bin/perl use warnings; use strict; my $data_start = tell *DATA; sub next_higher { my ($from) = @_; seek *DATA, $data_start, 0; my $so_far; while () { chomp; $so_far = $_ if $_ > $from && (! defined $so_far || $_ < $so_far); } return $so_far } use Test::More; is next_higher(11673326), 11673329; is next_higher(11673335), undef; is next_higher(11673321), 11673325; __DATA__ 11673326 11673329 11673325 11673330 11673321 11673335