#!/usr/bin/perl
$string="string";
open($fh, "data1.txt");
open($fh2,"data2.txt");
while ($row = <$fh>) {
chomp $row;
if ($row =~ /$string/ ) {
print $string."\n";
while ($row2 = <$fh2>) {
chomp $row2;
print $row2."\n";
}
} else {
print $row."\n";}
}