$test="LDAP://CN=MyPc,OU=MyOu,DC=NyDomain,DC=com"; $CN = substr($test, 10, index($test, ",") - 10); print "$CN\n";