# pseudo code that will not run unless you do some homework... use strict; use warnings; my $big_var = "Some massive\nstring\n"; # that big 200 line var goes here my $pattern = ""; open my $input input file open my $output output file while read line from input { print to output if pattern is matched { print $output $big_var } } close both files copy output over input