#!/usr/bin/perl -w use strict; sub do_stuff_with { # Silly proof of results my ($first, $text, $name, $last) = @_; print "First Bit: [$first]\n"; print "Some Text: [$text]\n"; print "The Name: [$name]\n"; print "Last Bit: [$last]\n\n"; } # Here's the meat... my $chunk; while ( chomp($chunk .= ) ) { if ( $chunk =~ /([^|]+)\|([^|]+)\|([^|]+)\|([^|]+)/ ) { my ($first, $text, $name, $last) = ($1,$2,$3,$4); $text =~ s/\s+/ /g; do_stuff_with($first, $text, $name, $last); $chunk = ''; } } __DATA__ friend|some text here|john|any friend|some other text here|mary|void friend|some text here but broken up into a few lines|simon|any friend|some more text|john|any