before: for ($j = 0; $j < @row; $j++) { $row[$j] =~ s/[^ -~]//g; $row[$j] =~ s/\|/:/g; } after: for (@row) { s/[^ -~]//g; s/\|/:/g; } j