There could be a problem with this line:
my ($day, $month, $day, $time, $year) = split(/ /, $j);
You are using $day twice.
I also prefer to use POSIX and then get my date string like this:
use POSIX;
my $md = strftime("%d %b %H:%M", localtime($m));
Just a preference though