in reply to sorting a filelist array by filename

Use a hash-of-arrays to group the paths by filename.

my %sourcesAndPaths; foreach (@classedSources) { my ( $dir, $file ) = m{ ^ (.+) / ([^/]+?) $ }x or do { warn "Can't parse '$_'"; next; }; push @{ $sourcesAndPaths{$file} }, $dir; } foreach my $file ( sort keys %sourcesAndPaths ) { my @dirs = @{ $sourcesAndPaths{$file} }; next if @dirs == 1; print "\n$file\n"; print "\t$_\n" for @dirs; }