Ruby なら、

re = /あい/

text = <<'EOT'
xあいxあい
yあ
いy
あい
EOT

puts dest = text.gsub( re, 'そら' )

出力
xそらxそら
yあ
いy
そら