my $min = $values[0]; my $max = $values[0]; for my $value (@values[1 .. $#values]) { $min = $value if $value < $min; $max = $value if $value > $max ; } #### my $firstMatchline; while () { next if !conditionMet($_); $firstMatchline //= $.; ... }