Listing 1. simple-search-1.pl

#!/usr/bin/perl -w
use strict;
use diagnostics;
# Open the file
my $filename = "test.txt";
open FILE, $filename
or die qq{Cannot read "$filename": $! };
# Iterate through each line of the file,
# printing all lines that match
while (<FILE>)
{
print if m/foo/;
}
close FILE;