#! perl -slw use strict; open GIF, '<:raw', $ARGV[ 0 ] or die $!; my $gif = do{ local $/; }; close GIF; ## Extract the colour table my @GCT = unpack '(A3)256', substr $gif, 13, 256 * 3; ## SWap the colours end to end @GCT = reverse @GCT; ## put the colour table back substr( $gif, 13, 256*3 ) = pack '(A3)256', @GCT; open OUT, '>:raw', 'modified.gif' or die $!; print OUT $gif; close OUT;