#! /usr/bin/perl use strict; use warnings; use 5.010; use File::Find; my $basedir = "."; my $extension = ".rec"; my @matched_dirs; sub wanted { # $File::Find::dir is the current directory name, # $_ is the current filename within that directory # $File::Find::name is the complete pathname to the file. push @matched_dirs, $File::Find::name if -d $_ && $_ =~ m/\Q$extension\E$/; } find( \&wanted, $basedir ); say "I have found:"; say $_ for @matched_dirs;