#!/usr/bin/perl use warnings; use LWP::Simple; use Email::Send; use Email::Send::Gmail; use Email::MIME::Creator; use Net::Ping::External qw(ping); use Tie::File; my $testfolder = "/Users/Appy/Desktop/"; my $to = "test1\@gmail.com"; my $from = "appy.test1\@gmail.com"; my $subject = "URLs not responding."; tie @file, 'Tie::File', $testfolder . "testfile2.txt" or die; foreach $URL (@file) { my $string1 = $URL; if ($string1 =~ m/ # Match \ping\s # 'Ping ' /ix # i = Ignore case # x = allow the regexp to go over multiple lines ) { print "$URL\n"; my $alive = ping(host => "$URL"); if ($alive) { print "$URL is active.\n"; } else { print "$URL is inactive\n";my $email = Email::MIME->create( header => [ From => $from, To => $to, Subject => $subject, ], body => "$URL is not working" ); my $sender = Email::Send->new( { mailer => 'Gmail', mailer_args => [ username => 'test12@gmail.com', password => '1234qwerty', ] } ); eval { $sender->send($email) }; die "Error sending email: $@" if $@ } } }