in reply to extract jpg from binary file

Binary data isn't any different from other data. For Perl, it's just a big string.

Assuming you have the memory, you can do:

my $jpeg = $binary_data; substr($jpeg, 0, index($jpeg, "\xFF\xD8") - 1) = ""; substr($jpeg, index($jpeg, "\xFF\xD9") + 1) = "";