use strict; use warnings; open(my $fh, "/path/to/file") or die $!; while(<$fh>) { last if $_ eq "#### end_ascii_header\n"; } #$fh is now positioned at the beginning of the binary data; do what you will