for my $e ($dom->find('span')->each) { if($e->text =~ /$mydate/ ){ my $myhtml = $e->parent->parent->parent->text; # do stuff with $myhtml } } #### #!/usr/bin/env perl use Modern::Perl; use LWP::Simple; my $date = $ARGV[0] || '4/23/012'; my $page = get('http://staweb.sta.cathedral.org/departments/math/mhansen/public_html/1112hcal/1112hcal.htm'); die "Couldn't get page" unless $page; my( $assignment ) = $page =~ m{ $date .+? (.+?)\s*

}sx; say $assignment;