my %function = ( allergies => sub { print_allergies ( my $var) }, immunizations => sub { print "in immunizations\n" }, ); my $dir = 'input_files'; die "can't opendir $!" unless opendir DIR, $dir; while (defined(my $file = readdir DIR)) { do { # print "The directory and file are $dir/$file\n"; die "Can't open input file $!" unless open IN, "< $dir/$file"; use File::Glob (); while (defined($_ = glob(' IN '))) { # print "Hello $_"; } # print_allergies (*IN); $function{$file}->() if exists $function{$file}; }; } closedir DIR; sub print_allergies{ local (*FH) = @_; while (){ next if (/^#/); print $_ ; } } #### # Input file for allergies # Date, Diagnosed By, Type, allergy, reaction,specifics 2009-05-16,Children's Hospital Boston,drugs,penicillin,Blue rash,This only happens on weekends 2009-05-17,Boston Medical Group,drugs,Vitamin B,Rash on torso,This happens after 9PM 2009-05-17,Children's Hospital,food,Diary,Upset stomach and gas, Happens after drinking whole milk