#!perl use strict; use warnings; while (){ chomp; my $aref = [ split /\s+/,$_ ]; print join ' ', 'Original Array:', @$aref,"\n"; my $start; my @copy=(); my $i=0; for (@$aref){ push @copy,$_; if ($_ == 6){ $start = $i unless defined $start; } elsif (defined $start && $_ == 7){ splice @copy, $start-$i-1; $start = undef; } ++$i; } print join ' ','Results:',@copy,"\n"; } __DATA__ 1 6 2 2 7 1 6 99 99 7 1 2 2 1 1 6 7 2 1 6 2 2 7 1 6 99 99 7 2 7 6 2 6 7 2 7 1 6 7 7 2 7 6 2 6 2 7 6 7 1 6 7 7 6 8 1 6 7