use warnings; my %flows = ( '0' => 1, '00' => 2, '0$' => 3, '0$more' => 4, 'foo0$' => 5 ); foreach (keys %flows) { # loop through keys of %flows setting $_ to each key in turn if (!($_ =~ "^0\$")) { print "Orig $_ not matched\n"; } else { print "Orig $_ matched\n"; } if (!($_ =~ m"^0\$")) { print "RE $_ not matched\n"; } else { print "RE $_ matched\n"; } print $/; } __DATA__ Orig 0 matched RE 0 not matched Orig 00 not matched RE 00 not matched Orig 0$more not matched RE 0$more matched Orig 0$ not matched RE 0$ matched Orig foo0$ not matched RE foo0$ not matched