# assuming you have a record string in $record and the field order is # always the same. my @fields = split(/\,/, $record); my $group = $fields[0]; # do this if you need to strip the "CN=" from the field $group =~ s/^CN=//; print $group . "\n";