$_="10101010000011110101000101001110110010100111"; (reverse, #I need it reversed so what follows will work s/(.)(.)(.)(.)/ #get the four digits && store them $a+=2**($_-1)if$$_/ee #take two to the $_power if #$$_ exists(e.g., $1 set, $2 set,etc) for 1..4 && #do it for each digit and s/1(?=\d)// && y/0-5/a-f/) #if 2-digit answer convert #to appropriate letter for hex for split /(....)/; #do this for all 4 digits #in $_ print $a, "\n";