I created the bit mask from the mask by replacing 0's by \x00 and 1's by \xff. Then, you can use bitwise & and can easily remove the resulting \x00's:
in reply to using bits to print part of a string
Updated: Using tr/ instead of s/ at line 10 speeds the method up.
my $string = join q(), map int rand 10, 1 .. 400_000;
my $mask = join q(), map int rand 2, 1 .. 400_000;
$mask =~ tr/01/\x00\xff/;
my $result = $string & $mask;
$result =~ tr/\x00//d;