my $s = "123 carrots 45 6 bananas 789"; while ($s =~ /(\d+)/g) { print "'$1' at position ", pos($s)-length($1), "\n"; pos($s) += 13; }