while(<DATA>){ if(/.*transaction="([^"]*)".*document_mode="([^"]*)".*/){ print "$1_$2.xml\n"; } } __DATA__ <PURCHASE_10 partner="food" version="1.50" timestamp="2009-03-10T09:56:55" transaction="PURCHASEORDER" document_mode="abc"> </PURCHASE_10>