in reply to Regex Doubt.

Use an anchor and negated character class (match comma followed by not comma followed by end of line)
=~ /(,[^,]+)$/
or use split
my $last = ( split /,/, $str ) [ 0 ] ;
See perlrequick it has several examples

Replies are listed 'Best First'.
Re^2: Regex Doubt.
by Anonymous Monk on Oct 16, 2012 at 03:12 UTC

    I have no permission to do it with split.

    The Regex way (=~ /(,^,+)$/) is giving me an error like the below,

    Can't find string terminator '"' anywhere before EOF at C:\Users\Raul\AppData\Local\Temp\dir6E94.tmp\Untitled line 4.

      I have no permission to do it with split.

      Sure you do

      The Regex way (=~ /(,^,+)$/) is giving me an error like the below,

      Not possible. If you want help, show your code.

        my $total_names = "Matthew,Thomas,Peter,Randy,George,Federick"; my $last_name = $1 if ($total_names =~ /(,[^,]+)$/ ); print "$last_name;

        Thanks Monk.