in reply to match the nth pattern

What have you tried so far?

A simple solution might to be match all occurrences and then select which you want to keep :

use strict; use warnings; my $string = '1potato 2potato 3potato 4 potato'; print +( $string =~ m/(\d+potato)/g )[2];

Just a something something...