#!/usr/bin/perl use strict; use warnings; my @Buffer = (); while () {    push @Buffer, $_;    if ($Buffer[-1] =~ /^"\$/) {        if (@Buffer <= 1) {            warn "Korrupte Daten vor Zeile $.";        }        else {            (my $fn = $Buffer[1]) =~ s~^\s*"([^"]+).*$~$1~;            unless (length $fn) {                warn "Kann Dateinamen vor Zeile $. nicht ermitteln.";            }            else {                chomp $fn;                $fn .= '.csv';                open(OUT, ">$fn") or die "Cannot open '$fn': $!";                print "[DEBUG] '$fn': open ok\n";                for my $buf (@Buffer) {                    print OUT $buf;                }                close(OUT) or warn "Cannot close '$fn': $!";                print "[DEBUG] '$fn': close ok\n";            }        }        @Buffer = ();    } } _ _DATA_ _ "beginn erster Datensatz" "" "" "matthew01" "" "" "texttexttexttetx text text" "" "" "texttext text" "" "98387" "text, text" "" "" "text" "" "" "" "" "" "text" 0.00 0.00 "$" "" "" "" "" "" "matthew02" "" "" "" "" "" "texttext text" "5330146514" "" "" "" "" "text, text" "" "" "" "" "" "text" "30.06.1999" "" "$" "" "" "" "" "" "matthew03" "" "" "" "" "" "texttext text" "5330146514" "" "" "" "" "text, text" "" "" "" "" "" "text" "30.08.2000" "" "$" "" "" "" "" "" "matthew04" "" "" "" "" "" "texttext text" "5330146514" "" "" "" "" "text, text" "" "" "" "" "" "text" "30.08.2000" "" "$" "" ""