#!/usr/local/bin/perl use strict; use warnings; my $raw_file="spectrebin.raw"; open (FILE,$raw_file); foreach my $line () { if ($line=~/^Binary:/) { #Switch to binary mode #NOTE: If you comment this line in, # it works but starts reading the file from the # start, which I do not want. I want it to # read only the binary portion #open (FILE,$raw_file); binmode(FILE) or die "ERROR> Could not read binary file"; my $buffer; while ((read (FILE, $buffer, 64))!=0) { my $binary = unpack("B64",$buffer); printf "Binary: $binary\n"; } #Do not read the binary part as ascii last; } else { #the ascii part printf "ASCII: $line"; } }