#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11151755 use warnings; my @paths = @ARGV; my %seen; while( my $path = shift @paths ) { $path eq '/data/logs/master' and next; unshift @paths, grep -d, <$path/*>; -f and $seen{join ' ', (stat)[0,1]}++ == 0 and save_file($_) for <$path/*auth.log>; }