my $file = 'dfedc.out'; my $ziel = "inactive_ports.txt"; my @inactive_ports; { local $/ = "\n\n"; open my $fh, '<', $file or die $!; while ( my $port_data = <$fh> ) { if ( $port_data =~ /Policy name\s*:\s*no policy applied/ ) { my ($port) = $port_data =~ /Port\s*:\s*([\w.]+)/; push @inactive_ports, $port; } } close $fh; } print "Inactive Ports: @inactive_ports\n"; #Zieldatei öffnen und schreiben open(OUT,">$ziel"); print OUT @inactive_ports; close(OUT);