修改后的代码如下,但我希望能够将没有出现的MAC也出现在output文件中..

#!/usr/bin/perl

use strict;
use warnings;

chomp (my $month=`date +%b`);
chomp (my $day=`date +%d`-1);

my $input="/home/gaochong/perl/input";
my $output="/home/gaochong/perl/output";
my $log_s="/home/gaochong/dhcp.log";
my $log="/home/gaochong/dhcp.log2";

open L_S,"$log_s";
open L,"> $log";
while (<L_S>) {
        print L $_ if (/$month\s+$day/);
}
close L_S;
close L;

open I,"$input";
open O,"> $output";
open L2,"/home/gaochong/dhcp.log2";

my $s;
while (<I>) {
        chomp ($s=$_);
        while (<L2>) {
                if (/DHCPDISCOVER from $s via (\d+.\d+.\d+.\d+)/i) {
                        print O $s . "   " . $1 . "\n";
                        last;
                }
        }
}
close I;
close L2;
close O;