\1 and $1 mean different things, most of the time.
In ordinary code, $1 refers to the text that was matched by the first pair of parentheses in the last regular expression match or substitution.
On the other hand, \1 is a reference to the constant scalar 1:
In a regular expression, $1 refers to the text matched by the first pair of parentheses in the previous regular expression, whereas \1 refers to the text matched by the first pair of parentheses in the current regular expression. So this program:
will print yes! if you pass it a pair of strings like foo fooxfoobar
In a substitution string (i.e. the yyy part of a s/xxx/yyy/ command), \1 and $1 both refer to the same thing - the text matched by the first pair of parentheses in the pattern. It's usually considered poor style to use the \1 version here.