Input loop

In Perl 6, filehandles etc. provide the .lines and .words methods which return lazy lists, and can thus they be iterated using a for loop...

Line-by-line (line endings are automatically stripped)

for "filename.txt".IO.lines -> $line {
    ...
}
for $*IN.lines -> $line {
    ...
}
for run(«find -iname *.txt», :out).out.lines -> $filename {
    ...
}
for run(«find -iname *.txt -print0», :nl«\0», :out).out.lines -> $filename {
    ...
}

Word-by-word

for "filename.txt".IO.words -> $word {
    ...
}