#!/usr/bin/perl -nw use constant ID => 'id_tag'; # ID what you searching use constant ID_LENGTH => length(ID); if (substr($_, 0, ID_LENGTH) eq ID ) { print "found:\n$_"; exit; } #### # [id_tag] [byte offset] id_tag1 0 id_tag2 123 id_tag3 463 ...