my $includepath="somefolder/somefolder/"; $html =~ s//&add_template($includepath.$1)/gexi; print $html; sub add_template{ #use File::Slurp qw/read_file/; if(!-f $1){ return "Could not include template '$_[0]' because: NO FILE" }elsif(!-r $1){ return "Could not include template '$_[0]' because: NO ACCESS TO FILE +"; } else { return read_file($_[0]); } }