f = ->a {a.group_by(&:upcase).select {|_,v| 1 < v.size}.values}p f.(readlines.map &:chomp)
aB.txt Ab.txt xx cd cD CD
[["aB.txt", "Ab.txt"], ["cd", "cD", "CD"]]
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!