my %cat = ('something' => 'stuff',); my $variable = 'something'; my $match; while (my ($key, $value) = each %cat) { if ($variable =~ /$key/) { $match = $value and last; } }