my $interesting_index; my $i = 0; while (!defined($interesting_index) and $i++ <= 10) { $interesting_index = $i if condition($i); } # spit an error if $interesting_index is still 'not defined'