#!/usr/bin/perl # http://perlmonks.org/?node_id=1193467 use strict; use warnings; my $aref = [1, 6, 2, 2, 7, 1, 6, 99, 99, 7]; my @copy; $_ == 6 .. $_ == 7 or push @copy, $_ for @$aref; use Data::Dumper; print Dumper \@copy;