in reply to Perl in Bash

Have you looked at the command(s) you are running in bash? set -x will show you what is run. Compare that with what you think should happen. Single quotes do not interpolate in bash.

Personally, I would write the complete program in Perl instead of keeping the loop in bash.