foreach my $words (@array) { if ($words =~ /(\s\s)$/) { #??? replace with just 1 \s } }