in reply to need help on unopened file handle

Why have you commented out this line?
# open($fh, '<', $infile) or die "Could not open logfile: $!";
Uncomment it and use
while(<$fh>)
as mentioned above