@lines=( "request(goodstring", "START_TIME,some goodness", "request(BADSTRING", "START_TIME,some bad stuff", "request(randomstring", "START_TIME,more goodness", ); for my $x (0..$#lines) { if($lines[$x]=~/request/) { (undef, $blah1) = split /\(/, $lines[$x]; if($blah1!~/BADSTRING/) { (undef, $blah2)=split /,/, $lines[$x+1];#<---Plus 1 gets next line print "$blah1:$blah2\n"; } } } ################# ## Output goodstring:some goodness randomstring:more goodness