sub md5files { my $dir = shift; # where the files are (must be a # direct path from root /) my $what = shift || '*'; # what files, default = '*' my $md5file = shift || "$dir/checksums.md5"; # default. my %hash_md5; my @t = split(/ /, $what); open (my $md5_outfh, '>', $md5file ) or die "Err: $!"; foreach my $f ( @t ) { foreach my $file2md5 ( grep { -f and $_ ne $md5file } <$dir/$f> ) { next unless my $md5 = md5calc( $file2md5 ); my ( $filename ) = $file2md5 =~ m{/([^/]+)$}; say $md5_outfh "$md5\t$filename"; $hash_md5{$md5} = $filename; } } close $md5_outfh; return %hash_md5 or die $!; # Consider 'use autodie;' }