use Data::Dumper; my $number=1234567812; my @tmp=split('',$number); my %count; foreach(@tmp){ $count{$_}=$count{$_}+1; } print Dumper \%count;