while () { next unless m/(\d+)\D+(\d+)/; # or warn && next, or die $min = $1 if $1 < $min; $max = $2 if $2 > $max; }