#!/usr/bin/perl; use strict; use warnings; use 5.012; my ($line, @newarr); my @hashfile = ; for my $line (@hashfile){ $line =~ tr/\$//; if ( $line =~ /VAR1/ ) { $line =~ s/VAR1/my \%hash/; push @newarr, $line; } else { push @newarr, $line; } } for $_( @newarr) { say $_; } __DATA__ $VAR1 = { '' => '', '362520' => 'Fktn and Name: fukutin[Rattus norvegicus]', '375790' => 'AGRN and Name: agrin[Homo sapiens]', '3339' => 'HSPG2 and Name: heparan sulfate proteoglycan 2[Homo sapiens]', '1428' => 'CRYM and Name: crystallin, mu[Homo sapiens]', }