$filename = '/usr/share/lib/dict/words'; $word = "cat"; open INPUT, $filename; while (<INPUT>) { chomp; if ($_ eq $word) { print "$word is in the dictionary.\n"; last; } }
The perl function `open' allows access to '$filename' through the file handle `INPUT'. This time, `while' works one line at a time through the file handle `INPUT' which refers to the file `$filename'. The perl function last exits immediately from a loop. Here, the loop is the `while'.