#! /usr/bin/perl my @collected; while ( my $line = ) { # line must end with 4 points if ( $line =~ m/\Q....\E$/ ) { chomp @collected; push @collected, $line; print "@collected"; @collected = (); } else { push @collected, $line; } } __DATA__ la le lu .... foo bar .... what ever ....