my $file = '/path/to/binaryfile'; # string to match, in hex my $matchstr = '53005f00560045005200530049004f004e005f0049004e0046004f0000000000bd04effe00000100'; # read in file and convert to a textual (hex) representation open(FILE,"$file") or die "Unable to open file: $!\n"; binmode(FILE); my $binhex = ''; while (eof(FILE) != 1) { my $buf; my $num_byte_read = read(FILE,$buf,16); foreach ($buf =~ m/./gs) { $binhex .= sprintf("%02x",ord($_)); } } close(FILE); # search it if ($binhex =~ /$matchstr(\S\S\S\S)(\S\S\S\S)(\S\S\S\S)(\S\S\S\S)/) { print "Found: " . join(',',($1,$2,$3,$4)); }