#!/usr/bin/perl -l use strict; use warnings; my $k = 5; my $file1contents = 'TACATCTCAAAACACTTTCATCTCACGACTACTACTACTACTTCAAAACACCATCAT'; my $file2contents = 'ACTTCAACATAACTACTATATACTACTCATACTACTACTCTTAAAACTACTATACTA'; $_ = "$file1contents\n$file2contents"; print "at position $-[0] is match $1" while /(.{$k,}) (?= .* \n .* \1 )/gx;