my $row = 'a,b,c,d,15'; my $str = $row =~ s/,[^,]*$//r; # $str now contains 'a,b,c,d'