#!/usr/bin/perl use Data::Dumper; %hash=( a=>1, b=>2, c=>3, aa=>4, ); @filterd_keys=grep {/a/} keys %hash; @filterd_hash{@filterd_keys}= @hash{ @filterd_keys }; print Dumper \%filterd_hash;