#!/usr/bin/perl use warnings; use Cwd; use File::Find; my $file_pattern ="*.txt"; find(\&d, cwd); sub d { my $file = $File::Find::name; return unless -f $file; return unless $file =~ /\Q$file_pattern\E$/; print "text file:$file\n"; }