while ($rest=~/\/mg) { $start=$1; $end=$2; $type=$3; $TM_part_to_store = "$start-$end"; $length_part="$start-$end"; if($type==1) { substr($topo_initial, ($start-1), ($end-$start+1), ($side1 x ($end-$start+1))); } elsif($type==2) { substr($topo_initial, ($start-1), ($end-$start+1), ($opposite{$side1} x ($end-$start+1))); } elsif($type eq 'B') { push @all_TMs_line, $TM_part_to_store; } else { substr($topo_initial, ($start-1), ($end-$start+1), ('U' x ($end-$start+1))); } }