use File::Find; my @filepaths; find sub { push @filepaths, $File::Find::name if /\.txt$/ }, '.'; # $_ is set to the current file basename