#!/usr/bin/perl use strict; use warnings; while (<>) { my $name; my @aname; chomp; $name = $_ if $_ /^cn:/; @aname = split(/\w./,$name); print "$aname[1]\n"; }