use strict; my $filename="0092042095432.dat"; #get this in as desired #THEN with substr my $fourchars=substr($filename,0,4); # OR with unpack my $fourchars=unpack("A4",$filename); #THEN if you want each character you can my @chars=split('',$fourchars);