#!/usr/bin/perl use strict; use warnings; my $usage ="$0 \n"; my $fileA = shift or die $usage ; my $fileB = shift or die $usage; open(FILEA, '<', $fileA) or die "could not open $fileA\n"; open(FILEB, '<', $fileB) or die "could not open $fileB\n"; my $file_a_content; { local $/=undef; # unset input record separator to slurp all into a string $file_a_content = ; close FILEA; } while (my $line = ) { $line=~s/SEARCHPATTERN/$file_a_content/; print $line; } close FILEB; #### $ middle_replacer.pl fileA fileB > fileC