use strict; use warnings; my ($str, $nth, $p); $str = "dsf,sdg,hjhgj,gjkh"; $p = -1; $nth = 3; while ($str =~ /,/g) { $p = pos($str) - length($&), last if !--$nth; } print substr($str, $p) if $p != -1;