use strict; use warnings;
use 5.010;


my $domain;
my $prot=0;

my $datei1;
my $datei2;
my $id = undef;
my $lc = @ARGV;
my @al=reverse('na'..'zz');
while (<>) {
    chomp;
	if ($lc > @ARGV) {
		$prot=0;
		$lc = @ARGV;
		open $datei1, '>', "$ARGV.Definitionen";
		open $datei2, '>', "$ARGV.to_align.fasta";

	}
    if ( my ($new_id) = /^>>\s(\S+)/ ) {
	    $prot++;
	    $domain=0;
		$id=$new_id;
	    say $datei1 "Modell: $ARGV $al[@ARGV] ID: $prot $_";
	}
	
	elsif ( defined $id and 
		 my ($start, $seq, $ende) = /^\s+$id\s+(\d+)\s+(\S+)\s+(\d+)/) {
	    $domain++;

	    say $datei1 "$domain S:$start E:$ende" ;

	    say $datei2 ">$al[@ARGV]", (sprintf "%04d%03d", $prot, $domain), "\n$seq";
	}
}
