in reply to Segmenting a file &deleting control characters

This bit is odd, for a file that was opened for write:
seek (OUT,2,1); read (OUT, my $num,4);
Why don't you just use a regex to pick out the segment markers?
if (/^(.*?)$delim\s\s(....)(.*)$/) {
Now the last bit of your last file is in $1, and the four characters to make into a filename are in $2. The start of your next file is in $3.

Look into the tr/// operator for deleting control characters.