my $exitWith; while ( my $zeile = <$dataFH> ) { if ( $zeile =~ /($typeRegExp)/ ) { if ( defined $exitCodes{$1} ) { $exitWith = $exitCodes{$1}; } my ($phy) = $zeile =~ / \b phy \s+ (\w+) /x; my ($state) = $zeile =~ / \b state \s+ (\w+) /x; my ($flags) = $zeile =~ / \b flags \s+ (\w+) /x; print "phy: $phy, state: $state, flags: $flags\n"; exit $exitWith if defined $exitWith; # <--- EDIT: Bedingung ergänzt } else { print "UNKNOWN\n"; } }