/(fred|wilma) (flintstone) \2/ # match "fred" or "wilma" and put them in bucket 1 # followed by "flintstone" and put that in bucket 2 # then match whatever is in bucket 2. Which in this # case must be "flintstone" so the regex is # equivelent to # /(fred|wilma) (flintstone) flintsone/ /(fred|wilma) (flintstone) \1/ # match "fred" or "wilma" and put them in bucket 1 # followed by "flintstone" and put that in bucket 2 # then match whatever is in bucket 1. Which in this # case could be "fred" or "wilma" so the regex is # equivelent to one of the following: # /(fred) (flintstone) fred/ # /(wilma) (flintstone) wilma/ #### #!perl -l print $_="the thing that that thing does"; /(\w+) that/ and printf '$&=%-20s $1=%-10s %s',$&,$1,$/; /($1) (\w+)/ and printf '$&=%-20s $1=%-10s $2=%-10s %s',$&,$1,$2,$/; /$1 (\w+) (\1)/ and printf '$&=%-20s $1=%-10s $2=%-10s %s',$&,$1,$2,$/; __END__ the thing that that thing does $&=thing that $1=thing $&=thing that $1=thing $2=that $&=thing that that $1=that $2=that