#! /usr/bin/perl use strict; use warnings; # https://www.perl-community.de/bat/poard/thread/18288 use File::Find; # for searching for files/directories use File::Spec::Functions qw( catfile ); # for creating portable file-paths use Cwd; # for determing current work directory my @directories = ( cwd, # search in current work directory ); my @matches; # storage for matching file paths sub find_ffn_files { return if ! -d $File::Find::name; # skip if not a directory my $dir = $File::Find::name; # short name of directory opendir my $dh, $dir or die "Cannot open '$dir': $!\n"; # read '.ffn' files from directory and create full file path my @files = map { catfile( $dir, $_ ) } grep { m/\.ffn$/ } readdir $dh; closedir $dh; # create array of array for matches push @matches, \@files if @files; } # search for files and fill @matches find( \&find_ffn_files, @directories ); # check @matches for my $matching_dir ( @matches ) { # each matching_dir is an array reference which contains # the full paths of the files found # process .ffn files per directory print join( " ", sort { $a cmp $b } @{ $matching_dir } ), "\n"; }