my @status; while () { chomp; push @status, $_; } my $current = 11673326; my $next = find_next_item($current, \@status); die "'$current' is either not found or has no next item\n" if ! defined $next; print "The next number after '$current' is '$next'\n"; sub find_next_item { my ($item, $list) = @_; my $next; for my $idx (0 .. $#$list) { if ($list->[$idx] eq $item) { $next = $list->[$idx + 1] if $idx <= $#$list; last; } } return $next; }