plantRegex = re.compile('^(Plant:)(.*)') kernelRegex = re.compile('^(Kernel:)(.*)') updateRegex = re.compile('^(Update:)(.*)') archRegex = re.compile('^(Architecture:)(.*)') providesRegex = re.compile('^(Provides:)(.*)') dependsRegex = re.compile('^(Dependes:)(.*)') filesRegex = re.compile('^(Files:)(.*)') allRegexps = ( plantRegex, kernelRegex, updateRegex, archRegex, providesRegex, dependsRegex, filesRegex ) for line in plantData: tab = line.strip() if tab == "" and plant != 0: continue for regex in allRegexps: m = oneRegex.match(tab) if m: # do something with m.group() break # and so on ...