http://www.perlmonks.org?node_id=181687


in reply to How can I read and print lines that has only one word from a file

So you want to open a file and print out all lines that only contain one word? If so, this should work:

open FILE, "file.txt" or die $!; while (<FILE>) { chomp; print "$_\n" if $_ =~ /^(\w+)$/; } close FILE;

Let me know if you have any questions.

Update: ++'s to tadman for the improvements below.