sub findfile { my $target = $_[0]; my $location = "/tmp/dir1"; my $foundfile; $target = qr/$target/; my $filename = find(sub { ($foundfile = $File::Find::name) if $File::Find::name =~ $target; }, $location); print $filename; }