local $/ = q{address}; # Set record separator to 'address'. open my $infile, '<', 'filename.txt' or die $!; print "This is the list of addresses\n", "here are the addresses\n"; while( <$infile> ) { chomp; # chomp removes the trailing record separator. s/^\s+|\s+$//g; next unless length; print "address $_\n"; }