#!/usr/bin/perl -w use strict; use LWP::Simple; open ("output","> outputfile.txt") || die ("Could not open output file $!"); my $html = get("http://www.htmladdress.com/file.html") or die "Couldn't fetch the site."; while($html=~ m{(.+\n.+(key\sword1|key\sword2|key\sword3).+\n.+)}gim){ my $text =$1; $text =~ tr[\n][ ]; print output "$text\n"; } close ("output");