#!/usr/bin/perl -w use feature qw{ state }; use strict; use warnings; for (1..5) { printf "Got the value %d\n", unique_integer(); } sub unique_integer { return ++(state $ncalls); } __END__ === Output === Got the value 1 Got the value 2 Got the value 3 Got the value 4 Got the value 5