my ($largest, $smallest) = (-9e9,9e9); # initialize to the wrong extremes ... for my $v (@array) { # [anonymous monk]'s [id://1203660]: single pass through loop, without sorting; more efficient than brostad's single sort $largest = $v if $v > $largest; $smallest = $v if $v < $smallest; }