use strict; use warnings; my ($low, $high) = qw /0 1e12/; my $search_number = int rand $high; my $guess; my $count = 0; while (1) { $guess = $low + int rand ($high - $low); last if $guess == $search_number; if ($search_number > $guess) { $low = $guess; } else { $high = $guess; } printf "%12d", $guess; print " - Range is $low - $high \n"; $count++; } print "Searched value is : $guess, found in $count tries \n";