import re source = open("1984_en.txt", "r") #source = open("joyce.txt", "r") destination = open("perec.txt", "w") regex = r'(\w*p+\w*e+\w*r+\w*e+\w*c+)' destination.write("Source: George Orwell's 1984\n\n\n") destination.write("Source: James Joyce, Almost complete works\n\n\n") sentences = [] for line in source: words = line.split(" ") for word in words: if re.search(regex, word): print(word) destination.write(word+'\n')