You could try something like:

@res = ($line =~ /cn=(.*?),/ig)

print $res[0];