#!/usr/bin/perl use strict; use warnings; open my $fh, '<', '/pfad/zur/datei' or die $!; local $/ = "\nproduct/productId"; while ( my $block = <$fh> ) { my $file = '/pfad/zur/ausgabe/' . $. . '.txt'; chomp $block; open my $out, '>', $file or die $!; print $out "product/productId" if $. != 1; print $out $block; close $out; } close $fh;