Both solutions almost work, only that I want the first instance to be 
replaced.
For example

1 4
1 4
1 5
1 4
1 5

one four
1 4
1 5
1 4
1 5

Steel Steel wrote:
> John Smith wrote:
>> Hi everyone,
>> 
>> I want to be able to run a program that will do a bunch
>> of searches specified in an array of strings, and replace the
>> first occurrence of those strings with strings specified on a
>> second array for a given text file.
>> 
>> What would be the best way to do this?
>> 
>> Ted.
> 
> search=%w[one four]
> replace=%w[1 4]
> to_do = search.zip(replace)
> File.open("file").each do |x|
>   to_do.each { |y| x.gsub!(y[0],y[1]);  }
>   puts x
> end

-- 
Posted via http://www.ruby-forum.com/.