in reply to check if image is monochromatic

A *jpeg* image? Considering jpeg compression isn't lossless, and it has serious problems with sharp colour changes (which are very common in black-and-white images), you'd be hard pressed to find a black-and-white image, that's still just black and white after a compression/decompression cycle.

Having said that, one way of doing it (untested):

my @out = `djpeg $file.jpg | ppmhist`; splice @out, 0, 2; if (@out == 2 && ($out[0] =~ /^\s*0+\s+0+\s+0\s/ && $out[1] =~ /^\s*255\s+255\s+255\s/ || $out[0] =~ /^\s*255\s+255\s+255\s/ && $out[1] =~ /^\s*0+\s+0+\s+0\s/)) { ... is black-and-white ... } else { ... has colours that are neither black, nor white ... }