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