while (my $token = $stream -> get_token()){ if ($token->[0] eq 'S') { # start tag if (exists $token->[2]->{href}) { # tag has href attribute print "PDF link!\n" if $token -> [2] -> {'href'} =~ m/\.pdf/; } } }