# Example: findone { coderef } @array # Example 1. WORKS while (my ($el,$index) = findone { m/good/ } @potentially_huge_array){ # Found match in $el do something. } # Example 2. DOESN"T WORK my @tokens = (tokens here); while ($line =<>){ chomp($line); die "$line is not a valid token" unless findone { m/^$line/ } @tokens; # Fails after all elements have been processed and will always fail from now on. }