#!/usr/bin/perl use strict; use warnings; my $file = '/path/to/src.file'; my $dir = '/path/to/destination_directory/'; my $number_of_entries = 20; # Anzahl Einträge pro Datei; my $counter = 0; { local $/ = "\nDATA"; my @entries = (); open(my $fh,"<",$file) or die $!; while(my $entry = <$fh>){ chomp $entry; $entry = 'DATA' . $entry unless($entry =~ /^DATA/); push(@entries,$entry); if(scalar(@entries) == $number_of_entries){ open(my $w_fh,">",$dir.$counter.".txt") or die $!; print $w_fh $_,"\n" for(@entries); close $w_fh; ++$counter; } } close $fh; } open(my $w_fh,">",$dir.$counter.".txt") or die $!; print $w_fh $_,"\n" for(@entries); close $w_fh;