#!/usr/local/bin/perl -w use strict; $|++; $/="\n."; while ( ) { print join ' ', /^\.?(\w+).+\n\t+\.\w+\W+(\w+)/; print "\n"; } __DATA__ .this is a line .and this is another line .again, a line. .Yet another line