Ubuntu, terminal window, bash shell:
alex@d120432:~$ echo $0
bash
alex@d120432:~$ echo $(perl -e 'print "a"x2')
aa
alex@d120432:~$ i=2
echo $i
2
alex@d120432:~$ echo $(perl -e 'print "a"x$i')
alex@d120432:~$
Is there syntax which allows to substitute $i with 2, so that the second echo command prints xx like the first one?