Tao Wang wrote: > Hi Everyone, > > I'm having a problem with extracting certain strings > within a line. I tried several ways, but not very > inefficient. Can somebody help me with it? thanks a > lot. > > The line might be one of the following: > KEY1 3 4 T KEY2 > > KEY1 3 4 T KEY2 456 67 KEY3 > > KEY1 3 4 T KEY2 456 67 KEY3 > > And I need to extract the information between KEYS. > > I'm using substr and pos to extract the information > now, but very complicated. Are there any better ways > to do it. please help me with it. I really appreciate > it. - tao
Hi Tao. Does this do what you want? Forgive me for not explaining it, but it 00:40 here - I'm off to bed! HTH, Rob use strict; use warnings; while (<DATA>) { chomp; my @values = /KEY\d\s+(.+?)(?=\s+KEY)/g; print join (", ", @values), "\n"; } __DATA__ KEY1 3 4 T KEY2 KEY1 3 4 T KEY2 456 67 KEY3 KEY1 3 4 T KEY2 456 67 KEY3 output: 3 4 T 3 4 T, 456 67 3 4 T, 456 67 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]