$img->read( data => $temp, type => 'pnm'); #### my $finger = 0; # or wherever the data starts while ($finger < length $temp) { substr( $temp, $finger, 3) = pack 'C3', reverse unpack 'C3', substr $temp, $finger, 3; $finger += 3; }