Check this Data.dat contains the input lines. This is working. open(Spooler, "Data.dat") or die "File does not exists\n"; while($spooler=) { #print "$spooler\n"; chomp($spooler); @matches = $spooler =~ /(\d+)ms/g; foreach $a (@matches){ print $a .","; } print "\n"; } Hope it helps!