use strict; use Fcntl; my %headers = ( 0 => "file-type", 1 => "file-size-in-bytes", 2 => "must-be-0", 3 => "must-be-0", 4 => "offset-to-raster-in-bytes", 5 => "size-of-following-header-in-bytes", 6 => "width-in-pixels", 7 => "height-in-pixels", 8 => "device-planes", 9 => "bits-per-pixel", 10 => "type-of-compression", 11 => "raster-size-in-bytes", 12 => "horizontal-pixels-per-meter", 13 => "vertical-pixels-per-meter", 14 => "number-of-colors-used", 15 => "number-of-important-colors", ); my $x = binary_contents("path/to/bitmap.bmp"); my @x = bmp_headers($x); for my $i(0..$#x){ printf "%-5s %-10s %-20s\n",$i,$x[$i],$headers{$i} } sub bmp_headers { # careful - 's' is endian sensitive my $t = 'a2Vn2V4s2V6'; my $x = shift; unpack($t,$x); } sub binary_contents { my $g = shift; sysopen(my $F, $g, O_RDONLY) or die "cant open: $g\n$!\n"; sysread($F, my $x, -s($g)); close $F; return $x; } #### open(my $FH, '>:raw', 'path/to/my/new/cool/bitmap.bmp'); print $FH $my_carefully_packed_binary_data