in reply to counting number of fileds

Use an array slice.
$fruits = "apple,banana,grape,orange"; @fruits = split ',',$fruits; # last three elements of the array @last3 = @fruits[$#fruits-2..$#fruits]; print join(',',@last3),"\n";