#!/usr/bin/perl -w use strict; open(FH, '-'); # using STDIN instead of a real file. while (){ my $entry = $_ =~ /:::(.*?):::/ms; open(FH2,'>filename'); print FH2 "$entry"; }