please use strict; if possible.
all the variables you use are global variables, so
they are overwritten by the recursive call. the
solution is to my all variables.
when you want to double the value of your bitstring,
you should call it with shift_bs(0,$source);.