foreach my $file (keys %hash){ foreach my $opt (keys %{$hash{$file}}){ if (!(defined $opt,$hash{$file}->{$opt})){ say '9809 ', join '|',$file,$opt,$hash{$file}->{$opt}; } $hash{$file}->{$opt}=~s/[^[:ascii:]]//gxms; my $lined=join ("\t",$file,$opt,$hash{$file}->{$opt})."\n"; }