foreach (keys %fhs) { my $fh = $fhs{$_}; if ($_ =~ /\.h\.new$/) { print $fh "#endif\n"; }