use strict; use warnings; my $file = 'test.binary'; my $size = 16; #bytes to write to file; open ( my $fh, '>', $file ) or die "Unable to open $file - $!\n"; binmode $fh; my $byte = 0; for ( 1..$size ) { $byte++; $byte %= 256; my $char = pack 'C', $byte; # I tried both print and syswrite. I get the same results with each. syswrite( $fh, $char, 1); #print $fh $char; } close $fh; print "\nDONE\n";