#!/usr/bin/perl use 5.014; use strict; use warnings; use autodie; my @arrX = (0,4194304,8388608); my $count = 0; my $max = 3; sub sendX { return if $count >= $max; my $data = shift @arrX; return if not $data; $count++; say $data; } for (1 .. $max) { sendX; }