System Output in to an Array or variable

hey guys in only new to scripting as such, but i have a problem.
i want to take the output of a search i do in the command line to then be in a variable but only a certain part of the output.

this this what im doing:

-bash-2.05b$ ldapsearch -x '(dn:=dc)' dc|grep dc=
# base <dc=james,dc=morey,dc=home,dc=com> (default) with scope subtree

so "# base <dc=james,dc=morey,dc=home,dc=com> (default) with scope subtree" is what is put out from the command line
now i want to make the "dc=james,dc=morey,dc=home,dc=com" into a variable but just that!!! not the other stuff.

this is so when i create my ldif file it will put it in automatically for you
so instead i will call "dc=james,dc=morey,dc=home,dc=com" some thing like $DC
dc=james,dc=morey,dc=home,dc=com =$DC

my $stuff = <<LDIF;

[LEFT][/LEFT]

[LEFT]dn: uid=$UserName,ou=$OU,ou=$OU2,dc=james,dc=morey,dc=home,dc=com
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: posixAccount
objectClass: shadowAccount
uid: $UserName
cn: $LastName $FirstName
givenName: $GivenName
mail: $UserName\@james.morey.com
sn: $FirstName
uidNumber: $UDI
gidNumber: $UDI
homeDirectory: /home/$UserName
loginShell: /bin/tcsh
userPassword: $b[/LEFT]

[LEFT][/LEFT]

[LEFT]dn: cn=$UserName,ou=$OU3,ou=$OU2,dc=james,dc=morey,dc=home,dc=comobjectClass: posixGroup
cn: $UserName
gidNumber: $UDI
description: Private group for the \"$UserName\" user"[/LEFT]

[LEFT][/LEFT]

LDIF

open MYLDIF, ">", "init.ldif";

print MYLDIF $stuff;

close MYLDIF;

 
ldapsearch -x '(dn:=dc)' dc|grep dc= | while read line
do
     DE=`echo $line | awk '{ n=split($1,arr,","); for(i=1;i<=n;i++){if(substr(arr,1,3)=="dc=") {if(j==1) str=str "," arr; else str=arr; j=1;}} printf("%s",str); }'`
     echo $DE;
done

It is assumed that "dc=value" pairs are comma separated.