in reply to Re: compare and merge files
in thread compare and merge files

May be this is helpful:
use strict; use warnings; use Data::Dumper; my @paths = qw( This/is/the/full/path/file.abc.part-1.txt This/is/the/full/path/file.abc.part-2.txt This/is/the/full/path/file.abc.part-3.txt This/is/the/full/path/file.def.part-1.txt This/is/the/full/path/file.def.part-2.txt This/is/the/full/path/file.ghi.part-1.txt This/is/the/full/path/file.jkl.part-2.txt This/is/the/full/path/file.mno.part-5.txt ); my %combo; foreach my $pathfile ( @paths ){ if( $pathfile =~ m/^.+file\.\w+?\.part-\d+\.txt$/ ){ (my $key = $pathfile) =~ s/part-\d+\.txt$/MERGED.txt/; push( @{ $combo{$key} }, $pathfile ); } else{ warn "$pathfile does not match expected format"; } } print Dumper(\%combo);