$str = "this is a sentence of words and I want the nth one"; $n = 4; # the word we want $a = 0; $a = 1 + index $str, $", $a while --$n; $word = substr $str, $a, -$a + index $str, $", $a; print "$word";