*>Sorry sir, this sounds too much like homework assignment to me. Yeah. Why not give a hint that works (but not in C): sed -e 's/111/1/g' -e 's/000/0/g' Well, to start with, we don't know whether it's a string processing HW, or a state machine homework? BillW -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads