#!/usr/bin/perl use File::Find; use strict; my $country; sub getCountry{ my $locn = shift; my $dir ='c:/temp/countries/'; find(sub{ txtsearch($locn) }, $dir); } sub txtsearch { my $locn = shift; if (-f $_) { open my $fh, "<", $_ or do { warn qq(Unable to open "$File::Find::name": $!); #checks permissions return; }; while(<$fh>) { if (/\Q$locn\E/) { my $country = (split '/', $File::Find::name)[-1]; print "$locn found in $country\n"; last ; #stops searching once found } } } }; getCountry("NY"); getCountry("London");