use threads ; use feature "say"; #use strict; use warnings; `tr -d '\n' modified_human_chr_1.txt`; my $input_file = "modified_human_chr_1.txt"; open my $hd, "<", $input_file or die "Couldn't open '$input_file' - $!"; my $text=<$hd>; chomp($text); my $window=5; my $i=0; LOOP:seek $hd,$i,0; read ($hd,my $substring,$window); my %hash; if(length($substring)==$window) { $hash{$substring}=$i; $i++; goto LOOP; } my $count = keys %hash; my $j=0; foreach my $pattern (keys %hash) { if($j<=$count) { my $thr="thread".$j; $$thr=threads->create(\&hunter,$text,$pattern); $j++; } } my @returns; foreach $thread (threads->list) { if ($thread->is_joinable() ) { push @returns, $thread->join; } if( scalar (threads->list) == 0 ) {last;} } print "@returns\n"; sub hunter { my ($text,$pattern) = @_ ; my $offset = 0; print "\n$pattern ($window)\n"; print '~' x $window,"\n"; my $pos=index $text,$pattern,$offset; while ($pos != -1) { print $pos+1," to ",$pos+$window,"\n"; $offset = $pos + 99; $pos = index($text, $pattern, $offset); } }