#!/usr/bin/perl -w use strict; my$line; my@fields; my@output; open (FILE, 'XXXX.txt') or die "can't open the file: $!"; open (FD, '>XXXX.txt') or die "can't open the file: $!"; while (defined ($line= )) { my@fields= split (/\s/ ,$line); my@output = grep /rs\d{5,}\b/ ,@fields; my$rs = join (':' , @output); $rs=~ s/:/\n/g; print FD "$rs"; } close FILE; close FD;