It's taking advantage of using a capture-group in split, which returns the split text with the intervening text being split upon. each_slice then groups the elements into two-element sub-arrays. map gets each two-element sub-array, does the join followed by the chomp.