use strict; use warnings; use feature 'say'; use Test::More tests => 2; use Test::NoWarnings; my %foo = ( a => 1, b => 0, c => '', d => undef ); my $lined = ''; foreach my $opt (sort keys %foo) { unless (defined $opt && defined $foo{$opt}) { no warnings 'uninitialized'; say '9809 ', join '|', $opt, $foo{$opt}; next; } # Only run these if $foo{$opt} is defined; $foo{$opt} =~ s/[^[:ascii:]]//gxms; $lined .= join ("\t", $opt, $foo{$opt})."\n"; } is $lined, "a\t1\nb\t0\nc\t\n";