if ($data[$i]=~ m/^\.\.BD/) { unless ... { $collect .= ',' . $data[i+1]; } } else { print $collect,"\n" if ($collect); $collect=''; if ($data[$i]=~ m/^\.\.AU/) { unless ... $collect= $data[i+1]; } } } }