Print all lines containing the word "target"
IO.foreach("somefile") do |line| puts line if line =~ /target/ end # Another way... file = File.new("somefile") file.each do |line| puts line if line =~ /target/ end