#!/usr/bin/perl use strict; my $record; while (){ s/\n/ /; if (/^\d+~/){ $record =~ s/ +$//; # trim trailing spaces printf "%s\n",$record if ($record); $record = $_; } else { $record .= $_; } } $record =~ s/ +$//; printf "%s\n",$record if ($record); __DATA__ 99~Arun~Kumar~Mobilenum: 1234-567 , from Earth Human 98~Mahesh~Babu~Mobilenum: 5678-901 , from Earth Human