$data = "DOCUMENT EXTRACTED FROM DB"; // etc open(WORDS, "commonwords.txt") || die ("Could not open common words file"); @stop_words = ; close(WORDS); $_ = $data; foreach $stopword(@stop_words){ $data =~ ### DO SUBSTITUTION HERE }