use File::Find; find(\&matches_regex, '.'); sub matches_regex { return undef unless (m/.+\.txt$/ && -f); unlink $File::Find::name,"\n"; ## scalar contains full path }