__DATA__ Some Company; Some Street 52 12345 City1 Another Company; Another Street 63 23456 City2 Yet Another Company; New Street 11 34546 City3 #### use strict; use warnings; while() { $_=~s/([\w; ]+\d+)\n(\d{5})/$1$2/gms; print; } #### use strict; use warnings; while() { $_=~s/(\d{5})/;$1;/g; $_=~s/\n//gms; $_=~s/(\d{5}; \w+)/$1\n/g; print; }