in reply to foreach problem

Complete stab in the dark: what if you don't use a prototype in your sub:
sub check_link {

You didn't specify which foreach you are having trouble with. Is it this one?

foreach $link(@links) {

Also, start printing things out and using Data::Dumper.