foreach (my $x = 0; $x < scalar @test; $x ++) { $test[$x] =~ s/ +$//; }