#!/usr/bin/perl -w use strict; use Benchmark; use File::Find; my @paths = (split/\:/,$ENV{PATH}); sub which1 { my $filename= "test.txt"; foreach my $pathname (@paths) { print "$pathname/$filename\n" if ( -e "$pathname/$filename" ); }; } sub which2 { my $filename = "test.txt"; finddepth sub {print "$_\n" if ( /$filename$/)} , @paths; } timethese (100, {'whichone' => \&which1, 'whichtwo' => \&which2}); #### [10:27:15 jhorner@gateway scripts]$ ./ch0as-1.pl test.txt Benchmark: timing 100 iterations of whichone, whichtwo... whichone: 0 wallclock secs ( 0.01 usr + 0.02 sys = 0.03 CPU) @ 3333.33/s (n=100) (warning: too few iterations for a reliable count) whichtwo: 14 wallclock secs (12.54 usr + 1.55 sys = 14.09 CPU) @ 7.10/s (n=100)