use Text::CSV; my $csv = Text::CSV->new(); while() { my ($name, $data) = split "="; $csv->parse($data); my @data = $csv->fields(); for my $i ( 0.. $#data ) { next unless $data[$i] eq 'ResGen'; # found a ResGen so see what we had 3 commas ago (do bounds check to0) next if $i -3 < 0; my $back_a_bit = $data[$i -3]; print chop($back_a_bit) eq '"' ? "$name: Found quote\n" : "$name: No quote\n"; } }