local $/ = undef; #slurp entire file my $string; open (my $FH, '<', $file1); $string = <$FH>; close $FH; open (my $FH, '<', $file2); $string .= <$FH>; #notice the concatenation close $FH;