%FileToFunction = ( "$file1", 'emailalert1', "$file2", 'emailalert2', "$file3", 'emailalert3', "$file4", 'emailalert4', "$file5", 'emailalert5', "$file6",'emailalert6' ); foreach my $key ( keys %FileToFunction ) { my $value = $FileToFunction{$key}; print "checking $path$key\n\n"; if (-e "$path$key") { print " it exists $path$key\n\n"; print " found ....: $value\n\n"; } else { print " could not find file $path$key generating alert running sub for $value\n\n\n"; &$value; } }