Hi -- On Tue, 28 Sep 2004, Matthew Margolis wrote: > The code below is supposed to scan through a string and put a ',' > before all zip codes. The code properly detects the zip codes and makes > the change in x but the change is never reflected in thestring. How can > I get these changes to exist outside of x's scope? > > thestring.each do |x| > if x =~ /\d{5}/ > puts "match" > x[-6] = "," > puts x > end > end The thing is, each substring, as returned by #each, is a new object, so nothing you do to them affects the original string. You could probably achieve what you want with: thestring.sub!(/\d{5}/) {|x| "#{x},"} David -- David A. Black dblack / wobblini.net