... my $dir ='/home/'; # perhaps $ENV{HOME} ? ... next unless ($file =~m/\. gi$/); # really you're looking for a file ending ". gi" perhaps $file =~m/\.gi$/ ... %links = elink_batch_to($db1, %params); # where does $db1 come from .. } # missing closing brace