#! c:\perl\bin use strict; use warnings; open (FH, "somefile.txt") or die("cannot open file"); foreach () { print if ($_=~/foo/); }