if ($input =~ /^\d+$/ and $input == $last + 1) { # process it } else { die "not consecutive from $input to $last"; }