#!/usr/bin/perl use strict; use warnings; my $path = '/media/sdb1/frames/neu/frames_20mb.dat'; my ($x, $y, $u, $z, $un) = 0; my $count = 10000000; my $HEADER = "\xff\xd8"; my $FOOTER = "\xff\xd9"; open my $dh, '<', $path; my $data = do {local $/; <$dh>}; my $RE_match_four_bytes = qr<\x55\x88[\x00-\x0b]\x10>; while ($data =~ m/($RE_match_four_bytes)/g) { ($x, $y, $u, $z) = split ("", $1); $un = ord($u); if ( $data=~ m/($HEADER.*?$FOOTER)/sg) { my $image = $1; $count++; my $image_name = "/media/sdb1/frames/new/$un/cam.$un.$count.jpg"; open my $fh, "> $image_name"; print $fh $image; } } close $dh;