use strict; use warnings; use Tie::Hash::Regex; tie my %hash, 'Tie::Hash::Regex'; %hash = ( 'foo.txt' => 1, 'bar.html' => 2, '..' => undef, '.' => undef, DEFAULT => undef, ); my $arg = shift || 'DEFAULT'; my $candidate = $hash{$arg}; die "invalid arg\n" unless $candidate; print "$candidate\n";