my @queue = qw( hellotheret hisissome randomstringd ata ); my %match = ( thisis => 1 ); #my $line_size = 5; my $line_size = 11; my $match_size = 6; my $count = 0; my $buffer = $queue[$count]; while(++$count < @queue) { $buffer .= $queue[$count]; warn "[$buffer] [$queue[$count]]\n"; for my $pos (0..length($buffer)-$match_size) { my $query = substr($buffer,$pos,$match_size); if(exists $match{$query}) { print "Got a match\n" } } substr($buffer,0,$line_size) = '' }