in reply to If logic fails foreach mistake

By your code, I assume that $filestamp gets set as a side effect of the filestamp function? This would be more easily followed if you returned the timestamp from the function and called it somewhat like.

my $filestamp=filestamp($logfile);

One problem I notice right away is that you are using single quotes to your argument to filestamp which means it always tests the string $logfile rather than the variable contents. So its likely that $filestamp is always set to 0 or more likely undef.

Unless you are using perl 4 then the & is optional for functions which have the ()'s after them. (and optional in other cases also)

Update:

Also the second foreach doesn't appear to be needed since each pass through the outer foreach will only return 1 logfile name to be processed.