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:)(.*)') for line in plantData: tab = line.strip() if tab == "" and plant != 0: continue if m = plantRegex.match(tab): # do something with m.group() elif m = kernelRegex.match(tab): # do something with m.group() elif m = updateRegex.match(tab): # do something with m.group() # and so on ...