#!/usr/bin/python import re #import the regular expression module infile = open("test.txt", 'r') lines = infile.readlines() infile.close() matchstr = re.compile(r"PSI3", re.IGNORECASE) for line in lines: line = matchstr.sub(r'PSI4', line) print line,