my $file = '/pfad/zur/datei.txt'; my @inactive_ports; { local $/ = "\n\n"; open my $fh, '<', $file or die $!; while ( my $port_data = <$fh> ) { if ( $port_data =~ /Status\s*:\s*Inaktiv/ ) { my ($port) = $port_data =~ /Port\s*:\s*(\d+)/; push @inactive_ports, $port; } } close $fh; } print "Inactive Ports: @inactive_ports\n";