sub insert_file { my $file = shift; my $path = "/home/www/artoflivingdelhi.org/$file"; unless (open(F, "<", $path)) { warn "insert_file: open of $path failed: $!"; print "\n"; } else { while () { print $_, "\n"; } # just copying what you have close(F); } } #### use strict; use warnings; use CGI qw(:standard); ... print header(); ... insert_file("frame.txt"); ... insert_file("local_frame_left.txt"); ...