foreach my $key (keys %$hashRef){ if ($key =~ /EventID/) { my $id = ($hashRef->{$key} & 0xffff); print $key . "\t" . "\"$id\"" . "\n"; }