use strict; use warnings; use feature 'bitwise'; while( ) { my ($n, $input) = split; my $width = length $input; my $result = ''; $result |.= substr 0 x $_ . $input, 0, $width for 0..$n; print "n = $n width = $width\n input $input\nresult $result\n\n"; } __DATA__ 2 1000 2 0100 2 0011 2 0000 0 010000000000100000000010000000010000000100000010000010000100010010 1 010000000000100000000010000000010000000100000010000010000100010010 2 010000000000100000000010000000010000000100000010000010000100010010 3 010000000000100000000010000000010000000100000010000010000100010010