#!perl use strict; use warnings; my $str = "a,b,c,d,e"; my $n = 1 + $str =~ tr/,//; # Field separator is a single char print "$n\n"; $n = 1 + (() = $str =~ /,/g); # Field separator is a regex print "$n\n";