#!/usr/bin/perl my $file = shift @ARGV || die "Gimme a file name to split up"; die "ugh - can't open '$file': $!" unless (open(INFILE, "<$file")); my $contents; # will hold entire vcard file contents { $/ = undef; # undef record separator $contents = <INFILE>; # in order to slurp in whole file } close(INFILE) || warn "Yo, weird prob closing file $!..."; # create a file for each vcard found my $name = 0; while ($contents =~ m/(BEGIN:VCARD.*?END:VCARD)/smg) { my $aVcard = $1; # contents of vcard # output to vcardNNN.txt file if (open(OUTFILE, ">vcard$name.txt")) { print OUTFILE $aVcard; close(OUTFILE); $name++; } else { warn "Could not open vcard$name.txt for write $!"; } }