raku.gg / beginner

Operators Galore

2026-03-10

Raku has one of the richest operator sets of any programming language. This is not complexity for its own sake. Each operator exists to make a specific pattern concise and readable. In this tutorial, we will cover the operators you will use most often, from basic arithmetic to the mind-bending magic of junctions.

Numeric vs String Operators

One of the first things to understand in Raku is that numeric and string operations use different operators. This eliminates an entire class of bugs common in other languages.

Comparison Operators

Operation Numeric String
Equal eq
Not equal != ne
Less than < lt
Greater than > gt
Less or equal <= le
Greater or equal >= ge
Three-way compare <=> leg
say 10 == 10; # True say "10" eq "10"; # True say 10 == "10"; # True (string coerced to number) say "aa" lt "bb"; # True (alphabetical comparison) say "2" lt "10"; # False! ("2" comes after "1" in string order) say 2 <; 10; # True (numeric comparison)
That last pair is exactly why separate operators matter. "2" lt "10" is False because string comparison goes character by character, and "2" is greater than "1". Use < for numbers, lt for strings, and you will never be surprised.

Arithmetic Operators

The basics work as you would expect:
say 10 + 3; # 13 say 10 - 3; # 7 say 10 * 3; # 30 say 10 / 3; # 3.333333 (Rat, not floating point!) say 10 ** 3; # 1000 (exponentiation) say 10 % 3; # 1 (modulo) say 10 div 3; # 3 (integer division)
Notice that 10 / 3 gives you a Rat (rational number), not a floating-point approximation. Raku uses rational arithmetic by default, which means 1/3 + 1/3 + 1/3 actually equals 1. No floating-point weirdness.
say (1/3 + 1/3 + 1/3) == 1; # True (try that in JavaScript!) say (1/3).WHAT; # (Rat)

String Operators

say "Hello" ~ " " ~ "World"; # Hello World (concatenation) say "ha" x 3; # hahaha (string repetition)
The ~ operator concatenates strings. The x operator repeats a string. These are distinct from + and so there is never confusion between numeric and string operations.

Ranges

The range operator .. creates a Range object:
my @digits = 0..9; say @digits; # [0 1 2 3 4 5 6 7 8 9] my @letters = 'a'..'f'; say @letters; # [a b c d e f] # Exclude endpoints with ^ say (0..^5).list; # (0 1 2 3 4) excludes 5 say (0^..5).list; # (1 2 3 4 5) excludes 0 say (0^..^5).list; # (1 2 3 4) excludes both
Ranges are lazy by default. Writing 1..Inf does not try to create an infinite list in memory; it generates values on demand.
for 1..5 -> $n { say "Number $n"; }

The Sequence Operator (...)

The sequence operator ... is one of Raku's most powerful features. It generates sequences by inferring patterns:
say (1, 2, 4 ... 64).list; # (1 2 4 8 16 32 64) - powers of 2 say (1, 3, 5 ... 15).list; # (1 3 5 7 9 11 13 15) - odd numbers say (1, 1, *+* ... 89).list; # (1 1 2 3 5 8 13 21 34 55 89) - Fibonacci!
The
+ is a WhateverCode expression meaning "add the previous two values." The sequence operator figures out the pattern from the initial values and generates terms until it hits the endpoint.
# Countdown say (10, 9, 8 ... 1).list; # (10 9 8 7 6 5 4 3 2 1) # Geometric sequence say (1, 3, 9 ... 729).list; # (1 3 9 27 81 243 729) # Infinite sequence (take first 8) say (1, 2, 4 ... *)[^8]; # (1 2 4 8 16 32 64 128)

Chaining Comparisons

Raku lets you chain comparison operators naturally, just like you would write them in mathematics:
my $x = 5; say 1 <; $x <; 10; # True (5 is between 1 and 10) say 1 <; $x <; 3; # False say 1 <;= $x <;= 5; # True my $y = 5; say $x == $y == 5; # True (all three are equal)
This is much cleaner than writing $x > 1 && $x < 10. The chain can be as long as you need:
say 1 <; 2 <; 3 <; 4 <; 5; # True say 1 <; 2 <; 3 <; 2 <; 5; # False (3 < 2 fails)

The Ternary Operator (?? !!)

Where most languages use ? : for ternary expressions, Raku uses ?? !!:
my $age = 20; my $status = $age >;= 18 ?? "adult" !! "minor"; say $status; # adult
The doubled characters make the ternary operator much easier to spot in code, especially when nested:
my $score = 85; my $grade = $score >;= 90 ?? "A" !! $score >;= 80 ?? "B" !! $score >;= 70 ?? "C" !! "F"; say $grade; # B

Smart Match ()

The smart match operator is context-sensitive. It adapts its behavior based on what is on the right side:
say 42 ~~ Int; # True (type check) say "hello" ~~ /hell/; # True (regex match) say 5 ~~ 1..10; # True (range membership) say "cat" ~~ "cat"; # True (string equality) say 7 ~~ (1, 3, 5, 7); # True (is it in the list?)
Smart match is the backbone of Raku's given/when construct (covered in the control flow tutorial).

Junctions (any, all, one, none)

Junctions are one of Raku's most unique features. A junction is a single value that simultaneously represents multiple values:
my $j = any(1, 2, 3); say 2 == $j; # True (2 equals any of 1, 2, 3) say 5 == $j; # False (5 does not equal any of 1, 2, 3)
There are four types of junctions:
# any - at least one must match say "found" if 5 == any(1, 3, 5, 7); # found # all - every value must match say "all big" if all(10, 20, 30) >; 5; # all big # one - exactly one must match say "just one" if one(1, 2, 2) == 1; # just one # none - no value should match say "none zero" if none(1, 2, 3) == 0; # none zero
The | operator creates an any junction, and & creates an all junction:
my $color = "red"; if $color eq "red" | "blue" | "green" { say "$color is a primary color"; # red is a primary color } my @scores = 85, 92, 78, 95; if all(@scores) >;= 70 { say "Everyone passed!"; # Everyone passed! }
Junctions can replace many common patterns that would otherwise require loops:
# Instead of looping to check if any element matches my @allowed = <;admin editor viewer>;; my $role = "editor"; if $role eq any(@allowed) { say "Access granted"; # Access granted } # Check that all values meet a condition my @temperatures = 36.5, 37.0, 36.8; if all(@temperatures) <; 38 { say "No fevers detected"; # No fevers detected }

Assignment Operators

Raku supports the usual compound assignment operators:
my $n = 10; $n += 5; # $n is now 15 $n -= 3; # $n is now 12 $n *= 2; # $n is now 24 $n /= 4; # $n is now 6 my $s = "Hello"; $s ~= " World"; # $s is now "Hello World"

Precedence Tip

When in doubt about precedence, use parentheses. But here is a quick mental model for the most common operators, from highest to lowest precedence:
  1. Method calls (.method)
  2. Exponentiation ()
  3. Multiplication, division (, /, %, div)
  4. Addition, subtraction (+, -)
  5. Concatenation (~)
  6. Comparisons (, <, eq, etc.)
  7. Logical and (&&, and)
  8. Logical or (||, or)
  9. Ternary (?? !!)
  10. Assignment (=, :=)

What is Next?

With operators under your belt, you are ready to put them to work in conditional statements and loops. Next up: control flow in Raku, from if to given/when to all the looping constructs you could want.