#!/usr/bin/perl use warnings; use strict; use IO::Handle; open (my $fh, '>', 'logfile.txt') || die "can't open logfile.txt"; open (STDERR, ">>&=", $fh) || die "can't redirect STDERR"; $fh->autoflush(1); my $need_work = 5; my $i_tried = 0; while ( $need_work > $i_tried ) { my $a; $i_tried++; print "$a\n"; #this generates a run time warning!!!!!! warn "this is warning $i_tried"; #an explict warning print $fh "I've tried $i_tried things as a test\n"; } __END__ logfile.txt contains: Use of uninitialized value $a in concatenation (.) or string at C:\TEMP\junk2.pl line 18. this is warning 1 at C:\TEMP\junk2.pl line 19. I've tried 1 things as a test Use of uninitialized value $a in concatenation (.) or string at C:\TEMP\junk2.pl line 18. this is warning 2 at C:\TEMP\junk2.pl line 19. I've tried 2 things as a test Use of uninitialized value $a in concatenation (.) or string at C:\TEMP\junk2.pl line 18. this is warning 3 at C:\TEMP\junk2.pl line 19. I've tried 3 things as a test Use of uninitialized value $a in concatenation (.) or string at C:\TEMP\junk2.pl line 18. this is warning 4 at C:\TEMP\junk2.pl line 19. I've tried 4 things as a test Use of uninitialized value $a in concatenation (.) or string at C:\TEMP\junk2.pl line 18. this is warning 5 at C:\TEMP\junk2.pl line 19. I've tried 5 things as a test