Split File by Pattern with File Names in Source File... Awk?

Hi all,

I'm pretty new to Shell scripting and I need some help to split a source text file into multiple files. The source has a row with pattern where the file needs to be split, and the pattern row also contains the file name of the destination for that specific piece. Here is an example:

source.txt:
-----------

------ BEGIN SPLIT: file_abc.txt
a
b
c
------ BEGIN SPLIT: file_def.txt
d
e
f
------ BEGIN SPLIT: file_gh.txt
g
h

What I need as a result, are 3 files, with the specified names and with the following content (excluding the pattern line with the file name existing in the source file):

file_abc.txt:
------------
a
b
c

file_def.txt:
-----------
d
e
f

file_gh.txt:
-----------
g
h

Is this something awk can help with? The source file can get pretty big and the script could generate 100-200 files after the split. I would appreciate any guidance or samples for this!

Thank you!

A solution in Perl.

#! /usr/bin/perl -w
use strict;

my ($line, @x);
open SOURCE, "< source.txt";
for $line (<SOURCE>) {
    if ( $line =~ /BEGIN SPLIT/ ) {
        @x = split /:/, $line;
        $x[1] =~ s/\s+//g;
        next;
    }
    else {
        open DEST, ">> $x[1]";
        print DEST "$line";
        close DEST;
    }
}
close SOURCE;

Works like a charm, thank you!