# Pg's approach my ($nth) = ($str =~ m/(\w+\s*){$index}/); # Grantm's approach my $idx = $index - 1; my ($nth) = $str =~ /(?:\w+\W+){$idx}(\w+)/;