!/usr/bin/perl use strict; use warnings; my @output = ( { file => "chr1.gens", pattern => qr/^0/ }, { file => "chr2.gens", pattern => qr/^1/ }, { file => "chr3.gens", pattern => qr/^2/ }, ); my $file = "test.txt"; open(IN,'<'.$file) || die "Can not open file $file: $!"; # open the output handles foreach my $o (@output) { my $file = $o->{file}; open(my $handle, "> $file") or die "Can't open $file: $!"; $o->{handle} = $handle; } while (my $line = ) { foreach my $o (@output) { my $pattern = $o->{pattern}; if($line =~ $pattern) { print $o->{handle} $line; # oder eben print $o->{handle} "$line\n"; # falls das zusätzlich \n erwünscht ist } } } # close the output handles foreach my $o (@output) { close $o->{handle}; } close IN;