Yes, there is a difference. As mentioned at http://www.ruby-doc.org/core/classes/Regexp.html#M001232
If =~ used with a regexp literal with named captures, strings (or nil) are assigned to local variables called capture names.
/(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ " x = y " p lhs #=> "x" p rhs #=> "y"
...
Assignment does not occur if the regular expression is placed on the right side.
" x = y " =~ /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ p lhs, rhs
String # ~ =
source share