#!perl
# open a text file - store it in $buffer
open(IPF,"<some_file_name") or
die "Failed to open input file, $!\n";
while (<IPF>) { $buffer .= $_; }
close IPF;
# open an output file to write to.
open(OPF,">some_other_file_name") or
die "Failed to open output file, $!\n";
# search for a given word
$search_word = 'the'; # probably find that one once of twice
while ($buffer =~ /\b$search_word\b/i) { print OPF "the\n"; }
close OPF;