$
variables are only set to matches into the block:
"Z_sdsd: sdsd".gsub(/^(Z_.*): .*/) { "#{ $1.strip }" }
This is also the only way to call a method on the match. This will not change the match, only strip
"\1" (leaving it unchanged):
"Z_sdsd: sdsd".gsub(/^(Z_.*): .*/, "\\1".strip)