while() { {local $/=''; s!(.*?),(.*?)!$1A$2!gs;} {local $/=''; s!(.*?),(.*?)!$1B$2!sg;} print; } __DATA__ This is to test. a, b a,b a,b