in reply to Splitting big file or merging specific files?

This one does both parts (along with creating the initial file).

It uses module Path::Tiny - if you don't have it, install it from CPAN.

#!/usr/bin/perl # http://perlmonks.org/?node_id=1193831 use strict; use warnings; use Path::Tiny; my $dir = 'folder'; my $input = 'bigfile.txt'; my $output = 'rebuiltfile.txt'; ################## create (fake) big file ################## path($dir)->mkpath; path("$dir/$input")->spew( map "line $_\n", 1..11 ); #################### split to 2 lines per file ############# my @lines = path("$dir/$input")->lines; my $number = () = glob "$dir/*"; path("$dir/bladibla_" . $number++ . '.txt')->spew(splice @lines, 0, 2) while @lines; #################### combine ############################### path("$dir/$output")->spew( map $_->[0]->lines, sort {$a->[1] <=> $b->[1]} map [ $_, "$_" =~ /(\d+)/ ], path($dir)->children( qr/^bladibla_\d+.txt$/ ));