#!/usr/bin/perl use strict; use warnings; open(FH, '< vhosts.conf'); my $content = do {local $/; }; my $start = q{}; my $finish = q{}; my @vhosts = $content =~ m!$start(.*?)$finish!sg; foreach my $vhost (@vhosts) { my ($name) = $vhost =~ /ServerName\s(\S+)/; open(OUT, "> $name.conf") or die "Can't open outfile $name: $!\n"; print OUT ""; print OUT $vhost; print OUT ""; close(OUT); } 1; #### ServerName www.foobar.com ServerAlias foobar.com DocumentRoot /var/www/foobar.com Order allow,deny Allow from all LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i -> %U\" \"%{User-Agent}i\ "" combined ErrorLog /var/log/apache2/foobar.com.error_log CustomLog /var/log/apache2/foobar.com.access_log combined Include conf/deflate.conf