#!/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});