use warnings; use strict; use autodie; open IN, "; close IN; foreach my $num (keys %rec) { my @count = ("@content" =~ /$num+/sg); open my $fh, ">iterations$num.txt"; print "$_\n" for @count; close $fh; }