my $bin = '101001100010100001'; $bin = reverse join " ", (reverse $bin) =~ /(.{1,4})/g; print $bin;