Ruby なら、こういう感じで、5つ書けばできるけど

# 末尾の改行を削除して、配列に読み込む

a = File.readlines( "a.txt", chomp: true )
b = File.readlines( "b.txt", chomp: true )