$ cat in.txt AaX ObU UcU XdR ZeZ UfH UgU FhA OiG UjX UkZ UlZ xmT $ perl -pe 'chomp if /^U/' in.txt AaX ObU UcUXdR ZeZ UfHUgUFhA OiG UjXUkZUlZxmT