I really appreciate your input. Thanks a lot.
I've tried changing to the code you wrote. No luck.
There must be something wrong with the setup of variables from the input file.
This works like a charm.
my $DISTNAME = 'cn=admin,ou=unit,o=organisation,l=locality,c=country';
my $DISTNAME2 =...