in reply to Understanding this regex
For "a single (and first) dn", use a scalar (not array) and exit the loop once you get it:
my $dn; while (<FILE>) { next unless /(<CN=.*?>)/; $dn = $1; last; } [download]