#!/usr/bin/perl use strict; use warnings; my @array = qw ( 0.99 0.99 0.99 0.99 ); my $count = 0; while (){ if (/^(\d\.\d{2,3}\s+)x(\s+\d\.\d{2,3})/){ print $1, $array[$count++], $2, "\n" } else { print } } __DATA__ 0.00 x 1.000 0.530 x 0.753 # output values for residue 1 0 # input 0.00 x 1.00 0.555 x 0.683 # output values for residue 2 0