I'm sure it can be improved a bunch, but here it is.
print pack'b*',do{map{$..=$|x$_;$|=$|?0:1;}map{split //}map{$0=!$0;$0? +$_:1 x$_;}q{42351534121234}=~/./g;$.};