use strict; use warnings; my %defs=(map {$_ => '-'}'a'..'p'); # generate simple example pairs my $test1='a1 $a $q $c 2b'; # use undefined hash. => ERROR my $test2='a1 $a $b $c 2b'; # only defined hashes => no ERROR print '<'.convert($test1).">\n"; print '<'.convert($test2).">\n"; sub convert { $_=shift; s/\$([\w_\d]+)/unless(defined($defs{$1})) { print "ERROR: <\$$1> is not defined in "; return($_); # ok or bad style ?? } $defs{$1} /egx; return($_); } #### ERROR: <$q> is not defined in