$text = "blue dog red cat red dog green cat pink dog black cat white dog";

@col = $text =~ /(\w+)\sdog/g;  # match dog and the word before it (the color)
                                # don't forget the "g" modifier!

print "The 3rd dog is $col[2]\n"; # Print the 3rd element of the array
