my @fields = ... ; my $binary = chr(0); defined( $fields[ $_ ] ) && length( $fields[ $_ ] ) and vec( $binary, $_, 1 ) = 1 for 0 .. $#fields;