... # set the Input Record Separator $/ = '@user_info_end'; while ( my $file_content = ) { # remove the Input Record Separator chomp $file_content; if ( $file_content =~ /\@user_info_start.*\n)(?s:(.*))/i ) { $user_info = $2; } ... } ...