in reply to Substr Perl
If I understand you correctly, you want to extract the "CN" term from the record string. Here is a somewhat brute-force approach but I think it demonstrates the principle you need to see.
# assuming you have a record string in $record and the field order is
# always the same.
my @fields = split(/\,/, $record);
my $group = $fields;
# do this if you need to strip the "CN=" from the field
$group =~ s/^CN=//;
print $group . "\n";
Given this and your prior question about storing multiple values in a single DB column, I think you should read up on Perl regex, split and join as well as other basic text processing functions. Perl excels at this kind of work, but you need to know what tools you have available.
It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.