#assuming $n contains the number ... my $first_n = substr($string, 0, $n); #to grab $n off the end my $last_n = substr($string, -1, $n);