#!/usr/local/bin/perl -w use strict; my ($titi, $tito); { $_ = ; if (m/^\.(\w+)/ .. m/^\t+\.\w+\W+(\w+)/) { $tito = $1 and next if defined $titi; $titi = $1 unless defined $titi; }; redo; } print "$titi, $tito\n"; __DATA__ .this is a line .and second is another line .again, a line. .Yet another line #### #!/usr/local/bin/perl -w use strict; my @arr; while () { push @arr, $1 if m/^\.(\w+)/ .. m/^\t+\.\w+\W+(\w+)/; }; print join " ", @arr; __DATA__ .this is a line .and second is another line .again, a line. .Yet another line