According to Avdi Grimm from RubyTapas
$1 is a global variable which can be used in later code:
if "foobar" =~ /foo(.*)/ then puts "The matching word was #{$1}" endOutput:
“The matching word was bar”
In short, $1, $2, $… are the global-variables used by some of the ruby library functions specially concerning REGEX to let programmers use the findings in later codes.
See this for such more variables available in Ruby.