for ($i = 0; $i <= $#sortedNames; $i++) { @temp = split/,/, $sortedNames[$i][0]; $temp[1] = reverse $temp[1]; $x = chop($temp[1]); $toOutput = reverse $temp[0]; $toOutput .= $x; $output = reverse $toOutput; print NEWFILE "$output\n"; }