$amount{ $ref->{accno} } = $ref->{amount};
   }
 
-  my $where = "AND c.id = $chart_id" if ($chart_id ne '');
+  my $where = $chart_id ne '' ? "AND c.id = $chart_id" : '';
 
   $query = qq{
     SELECT
 
 
   $intnotes .= "\n\n" if ($intnotes);
 
-  my $cc  = $main::locale->text('Cc') . ": $form->{cc}\n"   if $form->{cc};
-  my $bcc = $main::locale->text('Bcc') . ": $form->{bcc}\n" if $form->{bcc};
+  my $cc  = $form->{cc}  ? $main::locale->text('Cc') . ": $form->{cc}\n"   : '';
+  my $bcc = $form->{bcc} ? $main::locale->text('Bcc') . ": $form->{bcc}\n" : '';
   my $now = scalar localtime;
 
   $intnotes .= $main::locale->text('[email]') . "\n"
 
     push @values, $form->{accnoto};
   }
 
-  my $where_str = ' WHERE ' . join(' AND ', map { "($_)" } @where) if (scalar @where);
+  my $where_str = @where ? ' WHERE ' . join(' AND ', map { "($_)" } @where) : '';
 
   my $query     = qq|SELECT c.accno, c.description
                      FROM chart c
 
 sub _make_sort_spec {
   my ($class) = @_;
 
-  my %sort_spec = $class->_sort_spec if defined &{ "${class}::_sort_spec" };
+  my %sort_spec = defined &{ "${class}::_sort_spec" } ? $class->_sort_spec : ();
 
   my $meta = $class->object_class->meta;
 
 
                                         'to_table'   => 'delivery_orders',
                                         'to_id'      => $params{do_id});
 
-  my ($oe_id)  = $links[0]->{from_id} if (scalar @links);
+  my $oe_id  = @links ? $links[0]->{from_id} : undef;
 
   return $main::lxdebug->leave_sub() if (!$oe_id);
 
 
     $key = $params;
   }
 
-  my $where = ' WHERE ' . join(' AND ', map { "($_)" } @where) if (@where);
+  my $where = @where ? ' WHERE ' . join(' AND ', map { "($_)" } @where) : '';
 
   my $query = qq|SELECT * FROM tax $where ORDER BY taxkey|;
 
 
   my $options        = ref $key eq 'HASH' ? $key : { key => $key };
   $options->{key}  ||= "all_customers";
-  my $limit_clause   = "LIMIT $options->{limit}" if $options->{limit};
+  my $limit_clause   = $options->{limit} ? "LIMIT $options->{limit}" : '';
 
   my @where;
   push @where, qq|business_id IN (SELECT id FROM business WHERE salesman)| if  $options->{business_is_salesman};
     $extension            = 'xls';
   }
 
-  my $printer_code    = '_' . $self->{printer_code} if $self->{printer_code};
-  my $email_extension = '_email' if -f "$self->{templates}/$self->{formname}_email${language}${printer_code}.${extension}";
+  my $printer_code    = $self->{printer_code} ? '_' . $self->{printer_code} : '';
+  my $email_extension = -f "$::myconfig{templates}/$self->{formname}_email${language}.${extension}" ? '_email' : '';
   $self->{IN}         = "$self->{formname}${email_extension}${language}${printer_code}.${extension}";
 
   # Format dates.
 
   my $select_clause = join ', ',    map { $token_builder->($_, 1) } @select_tokens;
   my $join_clause   = join ' ',     @joins{ grep $joins_needed{$_}, @join_order };
   my $where_clause  = join ' AND ', map { "($_)" } @where_tokens;
-  my $group_clause  = ' GROUP BY ' . join ', ',    map { $token_builder->($_) } @group_tokens if scalar @group_tokens;
+  my $group_clause  = @group_tokens ? ' GROUP BY ' . join ', ',    map { $token_builder->($_) } @group_tokens : '';
 
   my %oe_flag_to_cvar = (
     bought   => 'invoice',
 
 
   my ($sth, $ref, $query);
 
-  my $query_transdate = ", current_date AS invdate" if !$form->{id};
+  my $query_transdate = !$form->{id} ? ", current_date AS invdate" : '';
 
   $query =
     qq|SELECT
 
   }
 
   if ($form->{periodic_invoices_active} ne $form->{periodic_invoices_inactive}) {
-    my $not  = 'NOT' if ($form->{periodic_invoices_inactive});
+    my $not  = $form->{periodic_invoices_inactive} ? 'NOT' : '';
     $query  .= qq| AND ${not} COALESCE(pcfg.active, 'f')|;
   }
 
 
   }
 
 
-  my $where = 'WHERE ' . join(' AND ', map { "($_)" } @filters) if (scalar @filters);
+  my $where = @filters ? 'WHERE ' . join(' AND ', map { "($_)" } @filters) : '';
 
   my $sortorder =  $params{sort} ? $params{sort} : "projectnumber";
   $sortorder    =~ s/[^a-z_]//g;
 
     add_token(\@where_tokens, \@where_values, col => $col, val => $params{$col}) if $params{$col};
   }
 
-  my $where = "WHERE ". join ' AND ', map { "($_)" } @where_tokens if scalar @where_tokens;
+  my $where = @where_tokens ? "WHERE ". join ' AND ', map { "($_)" } @where_tokens : '';
   my $query = "DELETE FROM record_links $where";
 
   do_query($form, $dbh, $query, @where_values);
 
   my $font_height       = $font_size + 2 * $padding;
   my $title_font_height = $font_size + 2 * $padding;
 
-  my $header_height     = 2 * $title_font_height if ($opts->{title});
-  my $footer_height     = 2 * $font_height       if ($pdfopts->{number});
+  my $header_height     = $opts->{title}     ? 2 * $title_font_height : undef;
+  my $footer_height     = $pdfopts->{number} ? 2 * $font_height       : undef;
 
   my $top_text_height   = 0;
 
 
   push @where,  'se.vc = ?';
   push @values, $vc;
 
-  my $where = ' WHERE ' . join(' AND ', map { "(${_})" } @where) if (@where);
+  my $where = @where ? ' WHERE ' . join(' AND ', map { "(${_})" } @where) : '';
 
   my $query =
     qq|SELECT se.id, se.employee_id, se.executed, se.closed, itime::date AS export_date,
 
   my $attribute  = $arg_ref->{attribute}; #
   my $dec_places = (defined $arg_ref->{dec_places}) ? $arg_ref->{dec_places}:undef;
 
-  my $where_type = "AND tax.report_headings.type = '$type'" if ( $type );
-  my $where_dcp  = "AND tax.report_variables.dec_places = '$dec_places'" if ( defined $dec_places );
+  my $where_type = $type ? "AND tax.report_headings.type = '$type'" : '';
+  my $where_dcp  = defined $dec_places ? "AND tax.report_variables.dec_places = '$dec_places'" : '';
 
   my $query = qq|
     SELECT $attribute
 
   $sort_order    = $filter{order}        unless $sort_order;
   my $sort_spec  = "${sort_col} " . ($sort_order ? " DESC" : " ASC");
 
-  my $where_clause = join(" AND ", @filter_ary) . " AND " if (@filter_ary);
+  my $where_clause = @filter_ary ? join(" AND ", @filter_ary) . " AND " : '';
 
   $select_tokens{'trans'} = {
      "parts_id"             => "i1.parts_id",
 
 
   my $dbh = $form->dbconnect(\%myconfig);
 
-  my $restriction  = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
+  my $restriction;
+  $restriction     = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
   $restriction    .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate})                                                          if $form->{fromdate};
   $restriction    .= qq| AND h.itime::date <= | . conv_dateq($form->{todate})                                                            if $form->{todate};
   if ($form->{mitarbeiter} =~ m/^\d+$/) {
 
   my $notes =
     qq|<textarea name=notes rows=$rows cols=50 wrap=soft $readonly>$form->{notes}</textarea>|;
 
-  my $department = qq|
+  my $department;
+  $department = qq|
               <tr>
                 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
                 <td colspan=3><select name=department>$form->{selectdepartment}</select>
 
     } (@{ $form->{all_departments} || [] });
   }
 
-  my $department = qq|
+  my $department;
+  $department = qq|
         <tr>
           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
     my $projectnumber_hidden = qq|
     <input type="hidden" name="project_id_$i" value="$form->{"project_id_$i"}">|;
 
-    my $copy2credit = 'onkeyup="copy_debit_to_credit()"' if $i == 1;
+    my $copy2credit = $i == 1 ? 'onkeyup="copy_debit_to_credit()"' : '';
 
     print qq|<tr valign=top>
     $accno
   $form->{title} = $locale->text("$title General Ledger Transaction");
   my $readonly   = ($form->{id}) ? "readonly" : "";
 
-  my $show_details_checked = "checked" if $form->{show_details};
-
-  my $ob_transaction_checked = "checked" if $form->{ob_transaction};
-  my $cb_transaction_checked = "checked" if $form->{cb_transaction};
+  my $show_details_checked   = $form->{show_details}   ? "checked" : '';
+  my $ob_transaction_checked = $form->{ob_transaction} ? "checked" : '';
+  my $cb_transaction_checked = $form->{cb_transaction} ? "checked" : '';
 
   # $locale->text('Add General Ledger Transaction')
   # $locale->text('Edit General Ledger Transaction')
 
   } else {
     if ($form->{draft_id}) {
-      my $remove_draft_checked = 'checked' if ($form->{remove_draft});
+      my $remove_draft_checked = $form->{remove_draft} ? 'checked' : '';
       print qq|<p>\n|
         . qq|  <input name="remove_draft" id="remove_draft" type="checkbox" class="checkbox" ${remove_draft_checked}>|
         . qq|  <label for="remove_draft">| . $locale->text('Remove Draft') . qq|</label>\n|
 
   my %subtotals = map { $_ => 0 } ('onhand', @subtotal_columns);
   my %totals    = map { $_ => 0 } @subtotal_columns;
   my $idx       = 0;
-  my $same_item = $form->{parts}[0]{ $form->{sort} } if (scalar @{ $form->{parts} });
+  my $same_item = @{ $form->{parts} } ? $form->{parts}[0]{ $form->{sort} } : undef;
 
   my $defaults  = AM->get_defaults();
 
 
 # calculate onhand
     if ($form->{"id_$i"}) {
       my $part         = IC->get_basic_part_info(id => $form->{"id_$i"});
-      my $onhand_color = 'color="#ff0000"' if  $part->{onhand} < $part->{rop};
+      my $onhand_color = $part->{onhand} < $part->{rop} ? 'color="#ff0000"' : '';
       push @ROW2, { value => sprintf "<b>%s</b> <font %s>%s %s</font>",
                       $locale->text('On Hand'),
                       $onhand_color,
     $extension            = 'xls';
   }
 
-  my $email_extension = '_email' if (($form->{media} eq 'email') && (-f "$myconfig{templates}/$form->{formname}_email$form->{language}${printer_code}.${extension}"));
+  my $email_extension = (($form->{media} eq 'email') && (-f "$myconfig{templates}/$form->{formname}_email$form->{language}${printer_code}.${extension}")) ? '_email' : '';
 
   $form->{IN}         = "$form->{formname}${email_extension}$form->{language}${printer_code}.${extension}";
 
 
   $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate}) unless $recursive_call;
 
   $form->{print_and_post} = 0         if $form->{second_run};
-  my $taxincluded            = "checked" if $form->{taxincluded};
+  my $taxincluded         = $form->{taxincluded} ? "checked" : '';
   $form->{update} = 1;
 
   &check_name("customer");
 
     $form->{quodate}      = $form->{transdate};
   }
 
-  my $payment_id = $form->{payment_id} if $form->{payment_id};
+  my $payment_id;
+  if ($form->{payment_id}) {
+    $payment_id = $form->{payment_id};
+  }
 
   # if the name changed get new values
   if (&check_name($form->{vc})) {
 
     map { $form->{selectdepartment} .= "<option>$_->{description}--$_->{id}\n" } @{ $form->{all_departments} || [] };
   }
 
-  my $department = qq|
+  my $department;
+  $department = qq|
         <tr>
           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
 
   my $form     = $main::form;
 
   my %params   = @_;
-  my $postfix  = '_login' if ($params{login_screen});
+  my $postfix  = $params{login_screen} ? '_login' : '';
 
   my %todo_cfg = TODO->get_user_config('login' => $form->{login});
 
 
   $::form->{title} = $::locale->text('Tax Office Preferences');
 
 
-  my $select_tax_office = $ustva->fa_auswahl($land, $amt, $ustva->query_finanzamt(\%::myconfig, $::form));
-  my $checked_accrual = q|checked="checked"| if ($::form->{method} eq 'accrual');
-  my $checked_cash = q|checked="checked"| if ($::form->{method} eq 'cash');
-  my $checked_monthly = "checked" if ($::form->{FA_voranmeld} eq 'month');
-  my $checked_quarterly = "checked" if ($::form->{FA_voranmeld} eq 'quarter');
-  my $checked_dauerfristverlaengerung = "checked" if ($::form->{FA_dauerfrist} eq '1');
-  my $checked_kz_71 = "checked" if ($::form->{FA_71} eq 'X');
+  my $select_tax_office               = $ustva->fa_auswahl($land, $amt, $ustva->query_finanzamt(\%::myconfig, $::form));
+  my $checked_accrual                 = $::form->{method}        eq 'accrual' ? q|checked="checked"| : '';
+  my $checked_cash                    = $::form->{method}        eq 'cash'    ? q|checked="checked"| : '';
+  my $checked_monthly                 = $::form->{FA_voranmeld}  eq 'month'   ? "checked"            : '';
+  my $checked_quarterly               = $::form->{FA_voranmeld}  eq 'quarter' ? "checked"            : '';
+  my $checked_dauerfristverlaengerung = $::form->{FA_dauerfrist} eq '1'       ? "checked"            : '';
+  my $checked_kz_71                   = $::form->{FA_71}         eq 'X'       ? "checked"            : '';
 
   my $_hidden_variables_ref;
 
   my $patterncount   = $form->{patterncount};
   my $elster_pattern = $form->{elster_pattern};
   my $delimiter      = $form->{delimiter};
-  my $steuernummer = $form->{steuernummer} if ($stnr eq '');
+  my $steuernummer   = $stnr eq '' ? $form->{steuernummer} : '';
 
   $form->{FA_Oeffnungszeiten} =~ s/\\\\n/\n/g;
 
 
 
 foreach my $file (@testitems) {
   my $clean = 1;
-  my $doc = PPI::Document->new($file) or do {
+  my $source;
+  {
+    # due to a bug in PPI it cannot determine the encoding of a source file by
+    # use utf8; normaly this would be no problem but some people instist on
+    # putting strange stuff into the source. as a workaround read in the source
+    # with :utf8 layer and pass it to PPI by reference
+    # there are still some latin chars, but it's not the purpose of this test
+    # to find them, so warnings about it will be ignored
+    local $^W = 0; # don't care about invalid chars in comments
+    local $/ = undef;
+    open my $fh, '<:utf8', $file or die $!;
+    $source = <$fh>;
+  }
+
+  my $doc = PPI::Document->new(\$source) or do {
     print $fh "?: PPI error for file $file: " . PPI::Document::errstr() . "\n";
     ok 0, $file;
     next;