diff --git a/star.wdl b/star.wdl
index b1c662f220c5d4b92661c5efd350af0de7639cfc..f1549134c6161872c7bc4b12c50ec11a10c92d35 100644
--- a/star.wdl
+++ b/star.wdl
@@ -104,7 +104,9 @@ task Star {
         Int runThreadN = 4
         # Use a margin of 30% index size. Real memory usage is ~30 GiB for a 27 GiB index. 
         Int memoryGb = 1 + ceil(size(indexFiles, "G") * 1.3)
-        String memory = "~{memoryGb}G"
+        # For some reason doing above calculation inside a string does not work.
+        # So we solve it with an optional memory string and using select_first.
+        String? memory
         # 1 minute initialization + time reading in index (1 minute per G) + time aligning data.
         Int timeMinutes = 1 + ceil(size(indexFiles, "G")) + ceil(size(flatten([inputR1, inputR2]), "G") * 180 / runThreadN)
         String dockerImage = "quay.io/biocontainers/star:2.7.3a--0"
@@ -137,7 +139,7 @@ task Star {
 
     runtime {
         cpu: runThreadN
-        memory: memory
+        memory: select_first([memory, "~{memoryGb}G"])
         time_minutes: timeMinutes
         docker: dockerImage
     }