#!/usr/bin/perl -w use strict; while () { if (/^id:/) { my ($city, $phone, $street, $zip) = (,,,); print "$city$phone$street$zip"; } } __DATA__ John, Doe Michael id:1234567890123 library:ACME City, state:PUEBLO, CO Phone:719-555-555 Street:1610 Sorrow AVE APT D Zip: 81004