my $myfile= 'C:/Documents and Settings/XXX/Desktop/YYY/test.txt'; open (FILE, "$myfile") || die "Can't open '$myfile': $!\n"; my @parse = ; close(FILE); foreach (@parse) { chomp; $_ =~ s/^(gi\d+?)(\|.+?\|.+?\|)\s+?(.+?)/$1 ($2) $3/g;