hi, > I know that each block always starts with and A in the first position of > the first line and ends with a T in the last position of the last line.
isnt it a T in the first position of the last row of the set? > I know that the second line starts with a B, and the data in the 5th space > on this line is the e-mail address, which is what I ultimately want. > However,... only line with a B in the bigining in set? > I am trying to get a list of email addresses for people who have ordered > products that begin with ADV. These can appear in multiple I lines. > Therefore you can never predict how many lines make up 1 order block. What about: #! /usr/bin/perl use strict; use warnings; my @email; open (FH, "<complex.txt") or die "$!"; local $/ = "\nA,"; # make \nA, the record seperator while(<FH>){ # read the next record my @fields = split ",|\n", $_; # split at , or \n my $b_index; # 0 for every new record for (my $i=0; $i<=$#fields; $i++){ if ($fields[$i] eq "B") {$b_index=$i; next;} elsif ($fields[$i] =~ /^ADV_.*/) {push @email, $fields[$b_index+4]; last;} } } works on the sample you provided. $/ (see perlvar) is the record seperator, usually \n. If really T would be the last char i the last row of the set, you could use "T \n" as $/ The way I do it assumes that the first and only first line of each set beginns with an A (and falsly buts that A at the end of the privious record, but doesnt matter for the aim her, does it?) The push assumes that there are always exactly 5 records between B and email and that this is the only line with a B in record (and comes before the lines with ADV_ lot of assumtions. Im sure there is better ways to do that - might be a strat, though. > "Online ordering is now available. Visit http://insidersadvantage.com for > details." Uh, given from your question, I better dont,, eh? Good luck, Wolf -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>