Thanks to all who responded. Much appreciated. It works, but please allow me to sight an example. The data pattern looks like this;
Aword Some Alphanumeric long string columnized format Some Alphanumeric long string columnized format Some Alphanumeric long string columnized format Aword Some Alphanumeric long string columnized format Some Alphanumeric long string columnized format Some Alphanumeric long string columnized format Aword Some Alphanumeric long string columnized format Some Alphanumeric long string columnized format Some Alphanumeric long string columnized format Aword Anotherword Some Alphanumeric long string columnized format Some Alphanumeric long string columnized format Some Alphanumeric long string columnized format Aword Some Alphanumeric long string columnized format Some Alphanumeric long string columnized format Some Alphanumeric long string columnized format ..............And so and so forth I have to slurp the file first in an array in order to do some clean up and parsing before I can get to this. As you al know when I slurp a file each line is stored in individual array element. All I want to do is find and store the values "Aword" and "Aword Anotherword" from the array and set the index to that array element where I found the above pattern. Hope this helps. My code never worked and here is how I was doing it. Note: Please note that this is just a quicky to print the element of the array containting a word or two words and just simply printing them. Thanks to All. -------------snipit---------------- my $line; my $i=0; for my $i (0..$#array) { if ($array[$i] =~ /^\S+\s*$/); { $line=$array[$i]; print "$line"; } } ----------------------------------- -----Original Message----- From: Roberto Etcheverry [mailto:[EMAIL PROTECTED] Sent: Monday, June 21, 2004 5:44 PM To: Naser Ali Cc: [EMAIL PROTECTED] Subject: Re: Pattern match It's difficult to answer if you do not post the code with some input to test it, but lets suppose you have this: my @array; @array = <FILE>; # slurp whole file Then is easy to get what you want: my @lines_with_single_word = grep /^\s*\S+\s*$/,array; # ^\s*\S+\s*$ means beginning of line, 0 or more whitespace, 1 or more non-whitespace (the word), 0 or more ws and the end of line Naser Ali wrote: >Hello, > >I have an array which was created by slurrping a whole text file. There >are certain element in the array after reading the files which contain >only one word. I want to only match those array elements which contain >a single word and print it. Tried every thing but in vain. I must be >doing something wrong, can any one please suggest the right way of >doing this. > >Thanks > > >