I have a certain script , which will segregate the log file and put the result.txt which is comming as expected. But i want to sent mail after this segregate log file attach it in the text file and sent. There is no error in this script but i need to enhance it. Please help me on how i can use it

```
#use Win32;

if (@ARGV != 2) {

    print "Please pass atleast one paramer\n";
    print "Usage:\n\t $0 <file_name><Pattern>\n";
    exit;
}
$File_name     = $ARGV[0];
$res_File_name = $File_name . "\.result\.txt";
$Pattern       = $ARGV[1]; 
chomp($Pattern);
open(FD,"$File_name") or die ("File '$File_name' could not be open \n");
open(WFD,">$res_File_name") or die("File $res_File_name could not be opened\n");

print "Enter begin match pattern: ";
$bgn = <stdin>; 
chomp($bgn);
print  $bgn;

print "Enter end match pattern: ";
$en = <stdin>; 
chomp($en);

while ($line = <FD>) {

    chomp($line);
    if ($line =~ /^$bgn/) { #seaching a patter at begining of the string.

        print WFD "Begin pattern '$bgn' matched with the line '$line'\n";
    }
    if ($line =~ /$en$/) { #seaching a patter at end of the string.

        print WFD "End pattern '$en' matched with the line '$line'\n";

      #exit;
    }
print WFD $_ if(/$Pattern/);
      # main();

       # use constant Service_Name =>'MyServ'
      #  use constant Service_Desc =>'MyServDesc'
       # sub main()

      # {
      # $opt=shift(@ ARGV)||""

      # if ($opt =~ /^(-i|--install)$/i)
      # {
         install _service( Service_Name, Service_Desc)

     #  }
      #  elsif ($opt =~ /^(-r|--remove)$/i)
  # {
     # remove_service(Service_Name);
  # }
  # elsif ($opt =~ /^(run)$/i)
#}

  # here we create a log file wth STDOUT and STDERR
  # The log file will be created with extension .log
  $log = $cwd . $bn . ".log";
 # open(STDOUT, ">> $log") or die "Couldn't open $log for appending: $!\n";
 # open(STDERR, ">&STDOUT") or die "Could";

close(FD);
close(WFD);

```