my $foo = $1 if $_ =~ /regex/; #### if ( $_ =~ /regex/ ) { my $foo = $1; $db_results->{$foo} = delete $db_results->{$_}; }