I've been using this idiom recently. >> line = " rows = 10 cols = 1 occupied cells = 0" => " rows = 10 cols = 1 occupied cells = 0" >> if line[/.*?(\d+).*?(\d+).*?(\d+)/] >> rows, cols, cells = $1.to_i, $2.to_i, $3.to_i >> end => [10, 1, 0] >> rows => 10 >> cols => 1 >> cells => 0