my $replace = 0; for ( my $x = 0; $x< @array; $x++ ) { if ( # pass of your condition ) { $array[$replace] = $array[$x]; $replace++; } }