my $html = <<'HTML'; HTML #### use strict; use warnings; my $htmlfile ='/var/www/html/xx/xxx/1204.html'; my $html = <<'HTML'; HTML #path of the included file my $includepath="/var/www/html/xx/xxx/"; if ($html =~ s{#include file="([^"]+)"}{&add_template($1)}gei) { print "the file has include file"; print $html; } else { print "doesn't have"; print $html; } sub add_template { my $file = shift; print "$file\n"; my $display_file="$includepath$file"; print $display_file, "\n"; if (-e $display_file){ #print "$display_file"; return read_file($display_file); } else { # warn "$display_file not found"; return ""; } }