in reply to Equal strings don't match!

Maybe $elem has a trailing newline character. Did you try to chomp @CMD?

Please use "code" tags instead of "pre" tags, and only use them around your code snippets. Your posting renders poorly. Re-read Writeup Formatting Tips.