"Debugging 101" suggests that a few well-placed
print statements might be in order. Before the loop, open a
<pre> block. Then, within, the loop, print a few key values, such as the raw date values and
$day_diff. That should help you narrow down the problem.
And are you really sure that it's a date difference problem? The following looks suspect to me:
$domain = unpack ("A4", $temp1[40]);
...
if (($domain eq "BBA") && ...
You're extracting a 4 character string, then comparing it to a 3 character string. Is that what you really mean to do?