$_ = "ABCOPCOGNHVCOHL"; my $P = sub { my($p, $q, $e, @s) = @_; $e, @s ? &{"C" ne $e ? $p : $q}($p, $q, @s) : () }; my $Q = sub { my($p, $q, $e, @s) = @_; ("O" ne $e ? () : "/"), &$p($p, $q, $e, @s) }; print join "", &$P($P, $Q, split //), "\n";