Filmmaker Mel Brooks is hardly known as a rock lyricist. But Aerosmith’s Steven Tyler and Joe Perry are more than happy to give him props for an assist on one of their best-known songs. As the rockers get ready for their induction into the Songwriters Hall of Fame on Thursday at the Marriott Marquis, they and the other tunesmiths being honored shared the secrets behind their hits. Here’s what they told us:

Steven Tyler and Joe Perry, “Walk This Way”

It began, says Perry, at a soundcheck in Hawaii where he came up with the initial guitar riff. Cut to New York a while later. Tyler had been working on lyrics for the “Toys in the Attic” album, and brought some along when he headed for a session at the Record Plant on West 44th Street.

“I left them in the cab,” says Tyler. “I was devastated.” He went upstairs to let his bandmates know, then walked down to an empty floor to rewrite them.

“I had a pencil, but I left paper upstairs,” Tyler says. “I had a cassette of what I’d put together as an arrangement. So I started singing along best I could and I sat on the steps and wrote the lyrics on the wall.”

Meanwhile, Perry says, “Some of us took a break and went out to the movies to see [Mel Brooks’] ‘Young Frankenstein.’ When we got back to the studio, we were throwing lines from the movie back and forth.”

“They came back and they were going ‘Walk this way,’” recalls Tyler, referencing a line Marty Feldman says to Gene Wilder in the film. “And it was just the perfect thing.”

“Dude Looks Like a Lady”

“This song started from a sampler that we’d bought. We were all farting in it, burping,” says Tyler. Perry was also playing his guitar into it, and came up what they would use as an intro. Then, says Tyler, “I had most of the lyrics written, but I didn’t know how to f - - kin’ start the song.

“The original lyric was ‘cruising for the ladies,’ ’cause it fit.

“I had gone out one night with the guys in Mötley Crüe, and Nikki Sixx and all of ’em were all going: ‘Dude, man, dude, I love your music,’ and “Dude, Steven, f - - king Aerosmith. What the f- - k , dude. Dude.’

“And I just f - - king lost my sh-t about it, so instead of ‘Cruising’ it was “DUDE.” Tyler then made to leap to “Dude looks like a lady,” and, he says, “I just looked at Joe and I remember saying, ‘Can I f - - king sing that?’ And he said, ‘Why not; you’ve sung everything else,’ you know. And the rest is history.”

Elton John and Bernie Taupin (to be honored with the Johnny Mercer Award), “Tiny Dancer”

Fans think this song is about Taupin’s first wife — he dedicated it to her on the album. But, he says, “It’s ironic, because she was neither tiny nor a dancer.”

Rather than a story about a specific person, Taupin says it’s “about being awestruck with a place and time.

“You have to bear in mind where we were coming from — that buttoned-up, cold old gray United Kingdom, [where] everyone was sort of repressed in their feelings. When we touched down in LA [in 1970] it was like we had died and gone to heaven.”

“Everywhere we went — the boutiques, restaurants, backstage in shows — not only were all the women characteristically beautiful, their [lack of] inhibitions were off the charts, and it was totally not what we were used to.”

He recalls “the way they moved, and those wonderful flowy outfits that they wore. It was all about movement and beauty. And dancers are very graceful.”

In addition, Taupin says, “There was this sort of mother-hen quality to them. They would sew your clothes — hence the line about ‘seamstress for the band.’

“If you’d look out in the crowd at the concerts there were just rows of beautiful faces, and in the my mind there was this thought that in their mind was this idea that they could marry a British rock star. Hence the line ‘you’ll marry a music man.’ ”

The line “Jesus freaks out in the street handing tickets out for God” stems from an original Fleetwood Mac member, Jeremy Spencer, who, says Taupin, “disappeared and joined up with this group called the Children of God, a sort of itinerant street church.

“Basically, in a nutshell, the whole song was a sort of salute to a generation of free spirits, a generation of cultural change.

“The real inspiration is sort of California teen class of 1970.”

Tony Hatch, “Downtown”

The song that became a No. 1 hit for Petula Clark in 1965 had its origins in New York City. British record producer Hatch visited the city looking for songs from Brill Building writers he could pitch to artists with whom he wanted to work. He stayed at the Essex House on Central Park South.

“On my first evening there, I walked down Broadway to Times Square,” Hatch says. “Because my geography wasn’t so good, I thought that Times Square was downtown. The images just stuck in my head — the best-lit places, shops open late, theaters . . .”

Back in Europe, Hatch visited Clark at her Paris home to pitch her some songs he’d gathered. She asked if he had anything he’d written himself. “I played her the bare bones of ‘Downtown,’ ” he says.

“Originally, I wasn’t thinking of a female artist for this song. I had someone like Ben E. King and the Drifters in mind.

“Even when we arrived at the recording session, I still had a couple of lines in the second verse that I hadn’t finished. So I just excused myself and went off to the gentlemen’s restroom and finished it off there.”

As for the “Seinfeld” episode in which Jerry and George analyze the lyrics, Hatch calls it “brilliant.”

Mick Jones, Lou Gramm of Foreigner, “Jukebox Hero”

These songwriting partners have different memories of writing “Jukebox Hero.” Gramm says, “The idea just popped into my head, because when I was growing up in Rochester, NY, I’d go to the Rochester War Memorial, with no money for a ticket. I’d stand by the backstage door, and now and then when security would open the door, I’d get a glimpse of what was going on. But even when the door was closed, I could hear what was going on.”

Jones recalls a soundcheck in Cincinnati. They signed autographs for fans as they entered the arena. That night when the band returned for the show, Jones says, “There was this one bedraggled kid left who had been waiting in the rain. We took pity on him and took him into the show with us. We got him on the side of the stage and gave him the royal treatment.

“I was looking at the kid, and he was just bedazzled. I wondered what he was thinking. And I suddenly saw a reflection of what we did . . . and how it was affecting kids. A lot of people had dreams of one day being onstage. It gave me a little bit of insight — and gave me the idea for the lyric.”

Jones says Gramm had come up with “[took] one guitar,” a big line in the song. And I had been working on this idea for “Jukebox Hero,” so we kind of put the two things together.”

The two wound up visiting each other at their Westchester homes to finish the song — Gramm in Katonah and Jones in Pound Ridge.

JD Souther, “Faithless Love” (Linda Ronstadt)

This one really made me feel like a professional songwriter — first of all because Linda recorded it, and about 20 other people,” says Souther, who now plays a country-music honcho on TV’s “Nashville.”

Souther says he put the title in the first line because he’d been listening to a lot of Hank Williams at the time and noticed that Williams did that a lot.

“I was writing it when Linda and I were living together in Beachwood Canyon, in the Hollywood Hill,” Souther recalls. He was about two verses in — to the line “Faithless love will find you and the misery entwine you” — and was playing his guitar when, he recalls, “I hear her paddling down the hall. She comes down and says, ‘That’s really beautiful, what is it?’ And I said, ‘I really don’t know yet, it’s on its way to being a song, I’m pretty sure.’ She said, ‘It’s so beautiful; if you finish it, I’ll sing it.’ That was pretty much all I needed to hear.”

Holly Knight, “Love Is a Battlefield” (Pat Benatar)

Knight was 20 when she moved from NYC to LA to work with producer/songwriter Mike Chapman. “The very first day I was writing with him,” says Knight, “Pat Benatar called him and said she need a hit song for her new album. He told her that her timing was perfect.”

Knight came up with a chord progression, and “We sort of phonetically mumbled what sounded cool,” she says.

“We wrote the entire song in one day, but for one line we spent two weeks on. That’s when I learned to fly paper airplanes. We would go hang out by his pool, and we would have a glass of wine or whatever and we had this game where we’d make planes. He’d be on one side and I’d be on the other, and I would shoot him an airplane across the pool with a line on it. And then he would shoot one back to me. It was always fun, and silliness and something good came out of it.”