#!/usr/bin/perl use strict; use warnings; my @rot; my @vio; my $lastmatchrot = 0; my $lastmatchvio = 0; while (<>) { my $matchrot = m~ROT~; my $matchvio = m~VIO~; push @rot, $_ if $matchrot or $lastmatchrot; push @vio, $_ if $matchvio or $lastmatchvio; $lastmatchrot = $matchrot; $lastmatchvio = $matchvio; } my $fh; open ($fh, ">Ausgabedatei.txt") or die "Kann Ausgabedatei nicht öffnen: $!"; print $fh "ROT:\n"; print $fh $_ for @rot; print $fh "\nVIO:\n"; print $fh $_ for @vio; close ($fh) or die "Kann Ausgabedatei nicht schließen: $!";