my $includepath="somefolder/somefolder/"; $html =~ s//&add_template($includepath.$1)/gexi; print $html; sub add_template{ my( $filename ) = @_; if(!-f $filename){ return "Could not include template '$filename' because: NO FILE" }elsif(!-r $1){ return "Could not include template '$filename' because: NO ACCESS TO FILE"; }else { return read_file($filename); } }