The following is my code
use warnings;
use LWP::Simple;
use WWW::Mechanize;
use WWW::Mechanize::Link;
my $mech = new WWW::Mechanize();
my $link = new WWW::Mechanize::Link();
my $file = 'source1.txt';
my $filename = 'links2.txt';
open(my $fh, '>', $filename) or die "Could not open file '$filename' $!";
open my $info, $file or die "Could not open $file: $!";
while( my $line = <$info>) {
$link = grep(/<a.*href=.*>/,$line);
print $fh $link->text;
}
close $fh;
when I try to run this I get the error Can't call method "text" without a package or object reference.