my @arr; foreach my $key ( keys %hash ) { if ( ref $hash{$key} ne 'HASH' && ref $hash{$key} ne 'ARRAY' ) { if ( ( defined $key ) && ( $key eq 'script' ) ) { push( @arr, $hash{$key} ); } } if ( ref $hash{$key} eq 'HASH' ) { foreach my $k ( keys %{ $hash{$key} } ) { my $str = $k . "=" . $hash{$key}{$k}; push( @arr, $str ); } } } print Dumper( \@arr ); my %freq = (); my @unique = grep { !$freq{$_}++ } @arr; print Dumper( \@unique ); Output : $VAR1 = [ 'FILE=fileA', 'err=99', 'foo.pm', 'FILE_READ=fileB', 'err=99' ]; $VAR1 = [ 'FILE=fileA', 'err=99', 'foo.pm', 'FILE_READ=fileB' ];