use strict; use warnings; use Posix qw(strftime); no strict 'refs'; no strict 'subs'; my $regex = 'WARNING'; my $dir = "L:\\vpn\\"; my $out = "L:\\vpn\\difflogs\\vpnwarn.out"; my $time = POSIX::strftime "%Y%m%d",localtime; my $newtime = ($time -1); my $log = $newtime.".log"; open OUT, ">$out", || die "Can't open outfile: $!"; open LOG, "$dir$log", || die "Can't open logfile: $!"; while () { if (m/$regex/g) { print OUT $_ . "\n"; } } close LOG; close OUT || die "Can't close VPN outfile: $!";