use warnings; use strict; my $bin = '1001100010100001'; print add_space($bin), "\n"; sub add_space { # Add space separator # Code adapted from perlfaq5: How can I output my numbers with commas added? local $_ = shift; 1 while s/^([01]+)([01]{4})/$1 $2/; return $_; } __END__ 1001 1000 1010 0001