# I assume 'snmpauto' is the name of a file. use File::Spec; my $snmp_file = find_snmpauto(); sub find_snmpauto { my $filename = 'snmpauto'; my @paths = qw(c:\\ /root); for (@paths) { my $name = File::Spec::catfile($_,$filename); return $name if -f $name; } # we hit here only if no file was found. die "Can't find a file '$filename' in the search path (path includes:" .join(', ',@paths) .")\n"; }