#!/usr/bin/perl use strict; use warnings; my @list; my $index = 0; while ( ) { chomp; $index++ if /^\s*$/; push @{ $list[ $index ] }, (split " ", $_, 2)[1]; } my @new_list = map { $list[1][$_] . ' ' . $list[0][$_] } 0 .. $#{$list[0]}; __DATA__ Guido bla1 ... Mike bla2 ... Klaus bla3 ... Guido Meyer Mike Smith Klaus Rothschild