#!/usr/bin/perl -l use strict; use warnings; my %foo = ( _foo => 'FOO', _bar => 'BAR', _baz => 'BAZ', zum => 'ZUM', # do not make this one a "real" variable ); { # limit the scope of the following 'no strict' no strict 'refs'; # There be magic here! This will get the keys from %foo # then attempt to remove the leading '_'. If it works, # the *modified* key gets passed along; otherwise, the # key is stripped from your processing list. We then # dynamically create a variable with the name of the # modified key and assign it the value of the unmodified # key in the hash. $$_ = $foo{"_$_"} for (grep { s/^_(.*)/$1/ } keys %foo); } # this is so we can speak the variable's name without Perl throwing a fit no strict 'vars'; print for ($foo, $bar, $baz, $zum); # should produce one 'unitialized' warning