use strict; my ($htm_file); opendir(CUR_DIR, ".") || die "Can't open current directory: $!\n"; foreach $htm_file (grep -f && -e && /\.htm$/i, readdir(CUR_DIR)) { open(HTM_FILE, "$htm_file") or die "Can't open $htm_file: $!\n"; while (){ # while there are lines in the file if(//i; # if it contains 'content' grab it print "$1\n"; # here's where you do something with it } } close HTM_FILE or die "Can't close $htm_file: $!\n"; } closedir CUR_DIR;