#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; my $str = 'a[bdy]dfjaPÑsdafÜ'; my $str_2 = 'WAP'; my $hoh_ref = { hash_1 => { a => 'a[bdy]dfjaPÑsdafÜ', b => 'WAP' }, hash_2 => { c => 'Te st' } }; print Dumper $hoh_ref; foreach my $key (sort keys %{$hoh_ref}) { foreach my $value (keys %{$$hoh_ref{$key}}) { # If not white space character or non printable character remove element if ($$hoh_ref{$key}{$value} !~ /[^[:print:]]/g || $$hoh_ref{$key}{$value} !~ /\s/) { delete $$hoh_ref{$key}{$value}; } elsif ($$hoh_ref{$key}{$value} =~ /[^[:print:]]/g) { while ($$hoh_ref{$key}{$value} =~ /[^[:print:]]/g) { print "Non Printable Characater:\t$&\n"; } } } } print Dumper $hoh_ref; __END__ $VAR1 = { 'hash_2' => { 'c' => 'Te st' }, 'hash_1' => { 'b' => 'WAP', 'a' => 'a[bdy]dfjaPÑsdafÜ' } }; $VAR1 = { 'hash_2' => {}, 'hash_1' => {} };