by
Jeremy Canfield |
Updated: June 25th, 2021
| Perl (Scripting) articles

Here is a basic example of how to subtract two numbers (integers) in Perl.

```
my $sum = (2 - 1);
print "$sum \n";
```

Which should return the following.

`1`

**Decrement**

-- can be used to decrement a value by one.

```
my $value = 10;
--$value;
print "$value \n";
```

Which should return the following.

`9`

**Decimal numbers**

By default, decimal will be used.

```
my $sum = (1.8 - 1.1);
print "$sum \n";
```

Which should return the following.

`1.7`

**Whole numbers**

The integer module can be used to round to whole numbers.

```
use integer;
my $sum = (2.4 - 1.1);
print "$sum \n";
```

Which should return the following.

`1`

Web design by yours truely - me, myself, and I | jeremy.canfield@freekb.net |