use warnings; use strict; package Fifo; sub new { my $self = []; return bless $self; } sub push { my $self = shift; my $id = shift; if (@_) { push @$self, [$id, \@_]; } else { push @$self, $id; } return scalar @$self; } sub pull { my $self = shift; return shift @$self; } sub remove { my $self = shift; my $id = shift; for (reverse 0..$#$self) { my $item = $self->[$_]; my $itemId = ref $item ? $item->[0] : $item; splice @$self, $_, 1 if $itemId eq $id } } 1; package main; my $fifo = Fifo->new; $fifo->push ('First person'); $fifo->push ('Second person'); $fifo->push ('Third person'); $fifo->remove ('Second person'); print "$_\n" while defined ($_ = $fifo->pull); #### First person Third person