Your code seems very badly organized if you can really mix into a single line of execution like that. You might look at refactoring the design. That said, caching the cached statements yourself is trivial with Perl–
my %query_map; # Actually declared in higher (more outer) scope.
if ( $x > 10 ) {
$query = "SELECT Name FROM Customers WHERE CustId = ?";
}
else {
$query = "SELECT Name FROM Sales WHERE SalesId = ?";
}
$query_map{$query} ||= $dbh->prepare($query);
$query_map{$query}->execute(@args_that_will_match_query);