Hello zeshan try
$str = "John D. Doe, SMD";
$str =~/(\w)\w+\s+(\w)\.\s+(\w)\w+\,.*/;
$initials = "$1$2$3";
print "Initials are $initials \n";
explanation
the J in John captured as (\w) thus $1 with more letters and then white space \w+\s+ OR John = (\w)\w+
the D in D. captured as (\w) thus $2 and a literal period \. and then white space \s+ OR D. = (\w)\.
the D in Doe captured as (\w) thus $3 with more letters and a literal comma \, OR Doe, = (\w)\w+\,
the rest after that is just accounted for with .*
initials just grabs the values held in the holding $1 , $2 and $3 variables.
thanks cornball
$str = "John D. Doe, SMD";
$str =~/(\w)\w+\s+(\w)\.\s+(\w)\w+\,.*/;
$initials = "$1$2$3";
print "Initials are $initials \n";
explanation
the J in John captured as (\w) thus $1 with more letters and then white space \w+\s+ OR John = (\w)\w+
the D in D. captured as (\w) thus $2 and a literal period \. and then white space \s+ OR D. = (\w)\.
the D in Doe captured as (\w) thus $3 with more letters and a literal comma \, OR Doe, = (\w)\w+\,
the rest after that is just accounted for with .*
initials just grabs the values held in the holding $1 , $2 and $3 variables.
thanks cornball