$dino = "I fear that I'll be extinct after a few million years."; if ($dino =~ /that (\w*) (\w*) (\w*) after/) { print "That said '$1' '$2' '$3' years.\n"; }