$_ = 'one two#three=four five=six#seven eight=nine'; print join '.', (/([^#= ]+)/g)[1,2,4..6]; #prints #two.three.five.six.seven