$position = 10; $id3_end = 10 + $id3_size; while ($position < $id3_end) { seek FH, $position, SEEK_SET; # read $frame_id, $frame_size, and $frame_flags $position += 10 + $frame_size; last if $frame_id =~ /\W/ || $position > $id3_end; # do something with $frame_id }