File(afile).open DO |af| 
 File(bfile).pen do |bf| 
  af.each do |line| 
   bf.puts(line) if line.match(/regex/)
END