use strict; use warnings; my $max = 4; #Largest expected index. while () { s/#.*$//; #Clear out the comments chomp; my @foo = split /,/; my $company = $foo[1]; #prime a variable with a company name if ($#foo > $max) { #If there are more elements than the max... my $range = (scalar @foo) - $max; #Get the top of the range $company = join '+', @foo[1..$range]; #The company name is in a slice } print "$company\n"; #do whatever with the data. } __END__ client,ABC Company, jwilkens,jdoe,mdeart #this one is fine client,Cornell,Thayil,Cameron & Sheppard, LLC, klivingston,amarison,pserton #thi s one is not client,Doe,Smith & Randall, Inc, jwaters,pfloyd,jjoplin #this one is not